Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Mips backend erroneously marks AT register as clobbered #31266

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR32294
Status CONFIRMED
Importance P enhancement
Reported by Kyle Butt (kyle+llvm@iteratee.net)
Reported on 2017-03-15 16:08:23 -0700
Last modified on 2019-02-06 07:06:30 -0800
Version trunk
Hardware PC Linux
CC lidija.besker@rt-rk.com, llvm-bugs@lists.llvm.org, simon.dardis@gmail.com, simon@atanasyan.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

The mips backend marks the AT (assembler temporary) register as clobbered for branch instructions. This prevents the branch coalescing pass from coalesing the branch because of the implicit def of AT. LLVM should not be producing assembler macros, and should treat the AT register as any other register. We should be compiling to the chip, and not to the assembler.

Quuxplusone commented 7 years ago

The MIPS backend currently marks the AT register as clobbered for branch instructions due to the implementation of the long branch pass. The AT register is required to compute the jump target when the target of the branch is out of range of the branch.

LLVM when targeting MIPS doesn't (or at least for MIPS32/MIPS64) produce macros as the assembly produced is in nomacro, noreorder, noat mode. LLVM considers AT a normal register.

I have a possible solution to not clobbering the AT register, but it requires reworking aspects of the long branch pass. To sketch it out, the implicit def of at is removed from branches. The long branch pass will modify the stack pointer to provide a spill slot for AT, the branch target will be computed in AT and we perform an indirect jump as normal. At the branch target, we insert an unconditional branch with a nop, followed by the reload of AT, and remove the spill slot from the stack.

Another approach maybe to see if it's possible to adjust the branch coalescing pass to tolerate cases where branches have implicit operands.

Quuxplusone commented 6 years ago

What is the status of this? Does anything need to be done?