Skip to content

Commit 4edb3d3

Browse files
Congzhe Caodancgr
authored andcommitted
[AArch64] Avoid pairing loads with same result reg
When pairing ldr instructions to an ldp instruction, we cannot pair two ldr destination registers where one is a sub or super register of the other. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D86906
1 parent cf11238 commit 4edb3d3

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,10 +1550,12 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
15501550
continue;
15511551
}
15521552
}
1553-
// If the destination register of the loads is the same register, bail
1554-
// and keep looking. A load-pair instruction with both destination
1555-
// registers the same is UNPREDICTABLE and will result in an exception.
1556-
if (MayLoad && Reg == getLdStRegOp(MI).getReg()) {
1553+
// If the destination register of one load is the same register or a
1554+
// sub/super register of the other load, bail and keep looking. A
1555+
// load-pair instruction with both destination registers the same is
1556+
// UNPREDICTABLE and will result in an exception.
1557+
if (MayLoad &&
1558+
TRI->isSuperOrSubRegisterEq(Reg, getLdStRegOp(MI).getReg())) {
15571559
LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits,
15581560
TRI);
15591561
MemInsns.push_back(&MI);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -run-pass=aarch64-ldst-opt %s -o - | FileCheck %s
2+
#
3+
# The test below tests that when the AArch64 Load Store Optimization pass tries to
4+
# convert load instructions into a ldp instruction, and when the destination
5+
# registers are sub/super register of each other, then the convertion should not occur.
6+
#
7+
# For example, for the following pattern:
8+
# ldr x10 [x9]
9+
# ldr w10 [x9, 8],
10+
# We cannot convert it to an ldp instruction.
11+
#
12+
# CHECK-NOT: LDP
13+
# CHECK: $x10 = LDRSWui $x9, 0
14+
# CHECK: $w10 = LDRWui $x9, 1
15+
# CHECK: RET
16+
---
17+
name: test1
18+
tracksRegLiveness: true
19+
body: |
20+
bb.0:
21+
liveins: $x9
22+
$x10 = LDRSWui $x9, 0 :: (load 4)
23+
$w10 = LDRWui $x9, 1 :: (load 4)
24+
RET undef $lr, implicit undef $w0
25+
...
26+
# CHECK-NOT: LDP
27+
# CHECK: $w10 = LDRWui $x9, 0
28+
# CHECK: $x10 = LDRSWui $x9, 1
29+
# CHECK: RET
30+
---
31+
name: test2
32+
tracksRegLiveness: true
33+
body: |
34+
bb.0:
35+
liveins: $x9
36+
$w10 = LDRWui $x9, 0 :: (load 4)
37+
$x10 = LDRSWui $x9, 1 :: (load 4)
38+
RET undef $lr, implicit undef $w0
39+
...

0 commit comments

Comments
 (0)