Skip to content

Commit cfa4fe7

Browse files
committed
[AArch64][LOH] Don't ignore regmasks in bundles by iterating over instrs.
The LOH pass iterates over instructions to build its custom register state machine, but it uses the top-level bundle iterator. This should be okay, because when the wrapper BUNDLE MI is built, it aggregates the register defs/uses in its instructions into MOs. However, that doesn't apply to regmasks, and accumulating regmasks across multiple instructions would be messy business. There are a couple AnalyzePhysRegInBundle (/Virt) helpers that do look at regmasks, but those don't fit in very well here. AArch64 has started to use a few bundle instructions, specifically as glorified pseudos for variant call instructions, which have regmasks. So the LOH pass ends up ignoring regmasks. Concretely, this has been wrong for a while, but, on aarch64, the most common bundle (rv_marker call) was always followed by the attached call instruction, a plain BL with a regmask. Which was properly detected by the pass. However, we recently started keeping the attached call in the bundle, so the regmask is now ignored. And the pass happily combines ADRPs, of say, x8, across the bundle, resulting in corrupt pointers later.
1 parent f3e76dc commit cfa4fe7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/Target/AArch64/AArch64CollectLOH.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ bool AArch64CollectLOH::runOnMachineFunction(MachineFunction &MF) {
559559
// Walk the basic block backwards and update the per register state machine
560560
// in the process.
561561
for (const MachineInstr &MI :
562-
instructionsWithoutDebug(MBB.rbegin(), MBB.rend())) {
562+
instructionsWithoutDebug(MBB.instr_rbegin(), MBB.instr_rend())) {
563563
unsigned Opcode = MI.getOpcode();
564564
switch (Opcode) {
565565
case AArch64::ADDXri:

llvm/test/CodeGen/AArch64/loh.mir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ body: |
190190
bb.14:
191191
liveins: $x10
192192
$x12 = ADDXri $x10, target-flags(aarch64-pageoff) @g0, 0
193+
194+
bb.15:
195+
; Should not produce a LOH when reg is clobbered by bundled regmask
196+
; CHECK-NOT: MCLOH_AdrpAdrp
197+
$x8 = ADRP target-flags(aarch64-page) @g0
198+
BUNDLE {
199+
BL @extfunc, csr_aarch64_aapcs
200+
}
201+
$x8 = ADRP target-flags(aarch64-page) @g1
193202
...

0 commit comments

Comments
 (0)