LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 22832 - Teach greedy register allocator about "free" patchpoint uses
Summary: Teach greedy register allocator about "free" patchpoint uses
Status: NEW
Alias: None
Product: new-bugs
Classification: Unclassified
Component: new bugs (show other bugs)
Version: trunk
Hardware: PC All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-06 20:49 PST by Andrew Trick
Modified: 2017-06-07 11:36 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments
bug.ll (790 bytes, application/octet-stream)
2015-03-06 20:49 PST, Andrew Trick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Trick 2015-03-06 20:49:08 PST
Created attachment 14002 [details]
bug.ll

There are several places where the spiller used by the register allocator should be fixed to reason about virtual register uses that can be spilled for free. Patchpoint operands that are in the set of "live values" (as opposed to call arguments) should be able to be folded by the target (see foldMemoryOperand). Generally, we consider runtime to be on the slow path, so we don't care if these values are in registers or stack locations. If we did care then the frontend should use call arguments instead with anyregcc convention.

This test case exposes a specific issue in RAGreedy::tryLocalSplit.
$ llc bug.ll -debug-only=regalloc

The test case pseudo-IR is:

0: %v1 = call()
1: inlineasm "clobber-all"
2: patchpoint %v1
3: patchpoint %v1

Because this is all in one basic block, RAGreedy tries to find an optimial local live range that can be assigned a physical register and spans as many uses as possible. It treats all uses as 

Fixing this is probably not hard but not trivial either because just eliminating patchpoint uses from the SpillKit's use set seems misleading and dangerous. Ideally the heuristics would be adjusted for these free uses instead. This is just involved enough that I won't have time to fix it myself.

My suggestion for anyone hitting this with a JIT is to try basic regalloc instead. It should avoid this problem and give you better compile time.
(see createTargetRegisterAllocator).
Comment 1 Andrew Trick 2015-03-07 15:44:27 PST
... my description was truncated.

RAGreedy::tryLocalSplit treats all uses the same. It then tries to find single range that covers the most users. In the above example, it finds the range [2,3]. It thens inserts a single reload before slot #2 and reuses %rbx. for %v1.