[llvm] 4edb3d3 - [AArch64] Avoid pairing loads with same result reg

Danilo C. Grael via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 13:26:40 PDT 2020


Author: Congzhe Cao
Date: 2020-09-22T16:25:08-04:00
New Revision: 4edb3d3646c46f15ca93bf19ed96a9169143ed6d

URL: https://github.com/llvm/llvm-project/commit/4edb3d3646c46f15ca93bf19ed96a9169143ed6d
DIFF: https://github.com/llvm/llvm-project/commit/4edb3d3646c46f15ca93bf19ed96a9169143ed6d.diff

LOG: [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

Added: 
    llvm/test/CodeGen/AArch64/aarch64-ldst-subsuperReg-no-ldp.mir

Modified: 
    llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
index d975b8bd04fe..8d90a9a18619 100644
--- a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
+++ b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
@@ -1550,10 +1550,12 @@ AArch64LoadStoreOpt::findMatchingInsn(MachineBasicBlock::iterator I,
             continue;
           }
         }
-        // If the destination register of the loads is the same register, bail
-        // and keep looking. A load-pair instruction with both destination
-        // registers the same is UNPREDICTABLE and will result in an exception.
-        if (MayLoad && Reg == getLdStRegOp(MI).getReg()) {
+        // If the destination register of one load is the same register or a
+        // sub/super register of the other load, bail and keep looking. A
+        // load-pair instruction with both destination registers the same is
+        // UNPREDICTABLE and will result in an exception.
+        if (MayLoad &&
+            TRI->isSuperOrSubRegisterEq(Reg, getLdStRegOp(MI).getReg())) {
           LiveRegUnits::accumulateUsedDefed(MI, ModifiedRegUnits, UsedRegUnits,
                                             TRI);
           MemInsns.push_back(&MI);

diff  --git a/llvm/test/CodeGen/AArch64/aarch64-ldst-subsuperReg-no-ldp.mir b/llvm/test/CodeGen/AArch64/aarch64-ldst-subsuperReg-no-ldp.mir
new file mode 100644
index 000000000000..96eb270b0606
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/aarch64-ldst-subsuperReg-no-ldp.mir
@@ -0,0 +1,39 @@
+# RUN: llc -mtriple=aarch64-linux-gnu -verify-machineinstrs -run-pass=aarch64-ldst-opt %s -o - | FileCheck %s
+#
+# The test below tests that when the AArch64 Load Store Optimization pass tries to
+# convert load instructions into a ldp instruction, and when the destination
+# registers are sub/super register of each other, then the convertion should not occur.
+#
+# For example, for the following pattern:
+#     ldr x10 [x9]
+#     ldr w10 [x9, 8],
+# We cannot convert it to an ldp instruction.
+#
+# CHECK-NOT: LDP
+# CHECK: $x10 = LDRSWui $x9, 0
+# CHECK: $w10 = LDRWui $x9, 1
+# CHECK: RET
+---
+name:            test1
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    liveins: $x9
+    $x10 = LDRSWui $x9, 0 :: (load 4)
+    $w10 = LDRWui $x9, 1 :: (load 4)
+    RET undef $lr, implicit undef $w0
+...
+# CHECK-NOT: LDP
+# CHECK: $w10 = LDRWui $x9, 0
+# CHECK: $x10 = LDRSWui $x9, 1
+# CHECK: RET
+---
+name:            test2
+tracksRegLiveness: true
+body:             |
+  bb.0:
+    liveins: $x9
+    $w10 = LDRWui $x9, 0 :: (load 4)
+    $x10 = LDRSWui $x9, 1 :: (load 4)
+    RET undef $lr, implicit undef $w0
+...


        


More information about the llvm-commits mailing list