[PATCH] D68344: [PowerPC] Remove assertion "Shouldn't overwrite a register before it is killed"

Yi-Hong Lyu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 2 10:06:24 PDT 2019


Yi-Hong.Lyu created this revision.
Yi-Hong.Lyu added reviewers: hfinkel, echristo, nemanjai, stefanp, lei, jsji, PowerPC, power-llvm-team.
Herald added subscribers: llvm-commits, shchenz, MaskRay, kbarton, hiraditya.
Herald added a project: LLVM.

The assertion is everzealous and fail tests like:

  renamable $x3 = LI8 0
  STD renamable $x3, 16, $x1
  renamable $x3 = LI8 0

Remove the assertion since killed flag of $x3 is not mandentory.


https://reviews.llvm.org/D68344

Files:
  llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
  llvm/test/CodeGen/PowerPC/remove-redundant-load-imm.mir


Index: llvm/test/CodeGen/PowerPC/remove-redundant-load-imm.mir
===================================================================
--- llvm/test/CodeGen/PowerPC/remove-redundant-load-imm.mir
+++ llvm/test/CodeGen/PowerPC/remove-redundant-load-imm.mir
@@ -346,3 +346,25 @@
     BLR8 implicit $lr8, implicit $rm
 
 ...
+---
+name:            overwrite_reg_before_killed
+alignment:       16
+tracksRegLiveness: true
+machineFunctionInfo: {}
+body:             |
+  bb.0.entry:
+    liveins: $x1
+
+    ; CHECK-LABEL: name: overwrite_reg_before_killed
+    ; CHECK: liveins: $x1
+    ; CHECK: renamable $x3 = LI8 0
+    ; CHECK: STD renamable $x3, 16, $x1
+    ; CHECK: STD killed renamable $x3, 8, $x1
+    ; CHECK: BLR8 implicit $lr8, implicit $rm
+    renamable $x3 = LI8 0
+    STD renamable $x3, 16, $x1
+    renamable $x3 = LI8 0
+    STD killed renamable $x3, 8, $x1
+    BLR8 implicit $lr8, implicit $rm
+
+...
Index: llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
+++ llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp
@@ -117,8 +117,6 @@
 
           if (!AfterBBI->modifiesRegister(Reg, TRI))
             continue;
-          assert(DeadOrKillToUnset &&
-                 "Shouldn't overwrite a register before it is killed");
           // Finish scanning because Reg is overwritten by a non-load
           // instruction.
           if (AfterBBI->getOpcode() != Opc)
@@ -134,12 +132,15 @@
           // It loads same immediate value to the same Reg, which is redundant.
           // We would unset kill flag in previous Reg usage to extend live range
           // of Reg first, then remove the redundancy.
-          LLVM_DEBUG(dbgs() << " Unset dead/kill flag of " << *DeadOrKillToUnset
-                            << " from " << *DeadOrKillToUnset->getParent());
-          if (DeadOrKillToUnset->isDef())
-            DeadOrKillToUnset->setIsDead(false);
-          else
-            DeadOrKillToUnset->setIsKill(false);
+          if (DeadOrKillToUnset) {
+            LLVM_DEBUG(dbgs()
+                       << " Unset dead/kill flag of " << *DeadOrKillToUnset
+                       << " from " << *DeadOrKillToUnset->getParent());
+            if (DeadOrKillToUnset->isDef())
+              DeadOrKillToUnset->setIsDead(false);
+            else
+              DeadOrKillToUnset->setIsKill(false);
+          }
           DeadOrKillToUnset =
               AfterBBI->findRegisterDefOperand(Reg, true, true, TRI);
           if (DeadOrKillToUnset)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68344.222840.patch
Type: text/x-patch
Size: 2587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191002/e820c182/attachment.bin>


More information about the llvm-commits mailing list