[PATCH] D100023: [PowerPC] fixup killed flags for ri + addi to ri transformation

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 7 00:15:14 PDT 2021


shchenz created this revision.
shchenz added reviewers: nemanjai, jsji, qiucf, PowerPC.
Herald added subscribers: kbarton, hiraditya.
shchenz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Fixup killed flags if `DefMI` and `MI` are not in the same basic blocks.

We may still get some verify errors if  `DefMI` and `MI`. This patch is just to fix one of them. That's why we keep the `FIXME` near the changes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100023

Files:
  llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir


Index: llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir
===================================================================
--- llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir
+++ llvm/test/CodeGen/PowerPC/convert-ri-addi-to-ri.mir
@@ -65,3 +65,35 @@
   $x3 = COPY %5:g8rc
   BLR8 implicit $lr8, implicit $rm, implicit $x3
 ...
+---
+name: killFlagSameBlock
+#CHECK : name : killFlagSameBlock
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+  liveins: $x3
+    %0:g8rc_and_g8rc_nox0 = COPY $x3
+    %1:g8rc_and_g8rc_nox0 = ADDI8 killed %0:g8rc_and_g8rc_nox0, -8
+    ; CHECK: %1:g8rc_and_g8rc_nox0 = ADDI8 %0, -8
+    %2:g8rc = LI8 0
+    ; CHECK: STD killed %2, 8, killed %0
+    STD killed %2:g8rc, 16, %1:g8rc_and_g8rc_nox0
+    BLR8 implicit $lr8, implicit $rm
+...
+---
+name: killFlagDifferentBlocks
+#CHECK : name : killFlagDifferentBlocks
+tracksRegLiveness: true
+body: |
+  bb.0.entry:
+  liveins: $x3
+    %0:g8rc_and_g8rc_nox0 = COPY $x3
+    ; CHECK: %1:g8rc_and_g8rc_nox0 = ADDI8 %0, -8
+    %1:g8rc_and_g8rc_nox0 = ADDI8 killed %0:g8rc_and_g8rc_nox0, -8
+
+  bb.1:
+    %2:g8rc = LI8 0
+    ; CHECK: STD killed %2, 8, killed %0
+    STD killed %2:g8rc, 16, %1:g8rc_and_g8rc_nox0
+    BLR8 implicit $lr8, implicit $rm
+...
Index: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -4784,7 +4784,12 @@
   LLVM_DEBUG(DefMI.dump());
 
   MI.getOperand(III.OpNoForForwarding).setReg(RegMO->getReg());
-  MI.getOperand(III.OpNoForForwarding).setIsKill(RegMO->isKill());
+  if (RegMO->isKill()) {
+    MI.getOperand(III.OpNoForForwarding).setIsKill(true);
+    // Clear the killed flag in RegMO. Doing this here can handle some cases
+    // that DefMI and MI are not in same basic block.
+    RegMO->setIsKill(false);
+  }
   MI.getOperand(III.ImmOpNo).setImm(Imm);
 
   // FIXME: fix kill/dead flag if MI and DefMI are not in same basic block.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100023.335738.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210407/02c824ed/attachment.bin>


More information about the llvm-commits mailing list