OSDN Git Service

AArch64: remove all kill flags when extending register liveness.
authorTim Northover <tnorthover@apple.com>
Mon, 26 Jun 2017 18:49:25 +0000 (18:49 +0000)
committerTim Northover <tnorthover@apple.com>
Mon, 26 Jun 2017 18:49:25 +0000 (18:49 +0000)
When we forward a stored value to a load and eliminate it entirely we need to
make sure the liveness of the register is maintained all the way to its use.
Previously we only cleared liveness on the store doing the forwarding, but
there could be other killing uses in between.

We already do the right thing when the load has to be converted into something
else, it was just this one path that skipped it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306318 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
test/CodeGen/AArch64/ldst-opt.mir

index c45c0b4..005f2d5 100644 (file)
@@ -808,7 +808,13 @@ AArch64LoadStoreOpt::promoteLoadFromStore(MachineBasicBlock::iterator LoadI,
     // Remove the load, if the destination register of the loads is the same
     // register for stored value.
     if (StRt == LdRt && LoadSize == 8) {
-      StoreI->clearRegisterKills(StRt, TRI);
+      for (MachineInstr &MI : make_range(StoreI->getIterator(),
+                                         LoadI->getIterator())) {
+        if (MI.killsRegister(StRt, TRI)) {
+          MI.clearRegisterKills(StRt, TRI);
+          break;
+        }
+      }
       DEBUG(dbgs() << "Remove load instruction:\n    ");
       DEBUG(LoadI->print(dbgs()));
       DEBUG(dbgs() << "\n");
index 5b3576d..9cb9528 100644 (file)
@@ -162,3 +162,22 @@ body: |
 # CHECK: UBFMWri undef %w1
 # CHECK: STRHHui undef %w3
 # CHECK: ANDWri undef %w3
+---
+name: promote-load-from-store-trivial-kills
+tracksRegLiveness: true
+body: |
+  bb.0:
+    liveins: %x0, %lr
+
+    STRXui %x0, %sp, 0 :: (store 8)
+    STRXui killed %x0, %sp, 2 :: (store 8)
+    %x0 = LDRXui %sp, 0 :: (load 8)
+    BL $bar, csr_aarch64_aapcs, implicit-def %lr, implicit %sp, implicit %x0, implicit-def %sp
+    RET %lr
+...
+# CHECK-LABEL: name: promote-load-from-store-trivial-kills
+# CHECK: STRXui %x0, %sp, 0
+# CHECK: STRXui %x0, %sp, 2
+# CHECK-NOT: LDRXui
+# CHECK-NOT: ORR
+# CHECK: BL $bar, csr_aarch64_aapcs, implicit-def %lr, implicit %sp, implicit %x0, implicit-def %sp