Skip to content

Commit 3d41ef6

Browse files
committed
AArch64: don't form indexed paired ops if base reg overlaps operands.
The registers involved might not be identical, but can still overlap (e.g. "str w0, [x0, #4]!").
1 parent 5d4f37e commit 3d41ef6

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
16131613
// If the stored value and the address of the second instruction is
16141614
// the same, it needs to be using the updated register and therefore
16151615
// it must not be folded.
1616-
bool IsMIRegTheSame =
1617-
getLdStRegOp(MI).getReg() == getLdStBaseOp(MI).getReg();
1616+
bool IsMIRegTheSame = TRI->regsOverlap(getLdStRegOp(MI).getReg(),
1617+
getLdStBaseOp(MI).getReg());
16181618
if (IsOutOfBounds || IsBaseRegUsed || IsBaseRegModified ||
16191619
IsMIRegTheSame) {
16201620
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits,

llvm/test/CodeGen/AArch64/ldrpre-ldr-merge.mir

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ body: |
1414
liveins: $w0, $w1, $x1
1515
; CHECK-LABEL: name: 1-ldrwpre-ldrwui-merge
1616
; CHECK: liveins: $w0, $w1, $x1
17-
; CHECK: early-clobber $x1, renamable $w0, renamable $w1 = LDPWpre renamable $x1, 5 :: (load (s32))
18-
; CHECK: STPWi renamable $w0, renamable $w1, renamable $x1, 0 :: (store (s32))
17+
; CHECK: early-clobber $x1, renamable $w0, renamable $w2 = LDPWpre renamable $x1, 5 :: (load (s32))
18+
; CHECK: STPWi renamable $w0, renamable $w2, renamable $x1, 0 :: (store (s32))
1919
; CHECK: RET undef $lr
2020
early-clobber renamable $x1, renamable $w0 = LDRWpre killed renamable $x1, 20 :: (load (s32))
21-
renamable $w1 = LDRWui renamable $x1, 1 :: (load (s32))
21+
renamable $w2 = LDRWui renamable $x1, 1 :: (load (s32))
2222
STRWui killed renamable $w0, renamable $x1, 0 :: (store (s32))
23-
STRWui killed renamable $w1, renamable $x1, 1 :: (store (s32))
23+
STRWui killed renamable $w2, renamable $x1, 1 :: (store (s32))
2424
RET undef $lr
2525
...
2626

llvm/test/CodeGen/AArch64/strpre-str-merge.mir

+27
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,30 @@ body: |
451451
RET undef $lr, implicit $x0
452452
453453
...
454+
455+
---
456+
name: 17-strwpre-strwui-same-reg-no-merge
457+
alignment: 4
458+
tracksRegLiveness: true
459+
liveins:
460+
- { reg: '$x0' }
461+
- { reg: '$x1' }
462+
- { reg: '$x2' }
463+
frameInfo:
464+
maxAlignment: 1
465+
maxCallFrameSize: 0
466+
machineFunctionInfo:
467+
hasRedZone: false
468+
body: |
469+
bb.0.entry:
470+
liveins: $x0, $x1, $x2
471+
; CHECK-LABEL: name: 17-strwpre-strwui-same-reg-no-merge
472+
; CHECK: liveins: $x0, $x1, $x2
473+
; CHECK: early-clobber renamable $x0 = STRWpre renamable $w1, renamable $x0, 24, implicit $w0, implicit-def $w0 :: (store (s32))
474+
; CHECK: STRWui renamable $w0, renamable $x0, 1 :: (store (s32))
475+
; CHECK: RET undef $lr, implicit $x0
476+
early-clobber renamable $x0 = STRWpre killed renamable $w1, killed renamable $x0, 24 :: (store (s32))
477+
STRWui renamable $w0, renamable $x0, 1 :: (store (s32))
478+
RET undef $lr, implicit $x0
479+
480+
...

0 commit comments

Comments
 (0)