[PATCH] D49052: RenameIndependentSubregs: Fix handling of undef tied operands

Mark Searles via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 6 20:24:05 PDT 2018


msearles created this revision.
msearles added reviewers: arsenm, MatzeB.
msearles added a project: AMDGPU.
Herald added subscribers: nhaehnle, wdng.

Ensure that, if updating a tied operand pair, to only update that pair.


https://reviews.llvm.org/D49052

Files:
  lib/CodeGen/RenameIndependentSubregs.cpp
  test/CodeGen/AMDGPU/rename-independent-subregs.mir


Index: test/CodeGen/AMDGPU/rename-independent-subregs.mir
===================================================================
--- test/CodeGen/AMDGPU/rename-independent-subregs.mir
+++ test/CodeGen/AMDGPU/rename-independent-subregs.mir
@@ -2,6 +2,7 @@
 --- |
   define amdgpu_kernel void @test0() { ret void }
   define amdgpu_kernel void @test1() { ret void }
+  define amdgpu_kernel void @test2() { ret void }
 ...
 ---
 # In the test below we have two independent def+use pairs of subregister1 which
@@ -67,3 +68,20 @@
     S_NOP 0, implicit %0.sub2
 
 ...
+# In this test, there are two pairs of tied operands
+# within the inline asm statement:
+# (1) %0.sub0 + %0.sub0 and (2) %0.sub1 + %0.sub1
+# Check that renaming (2) does not inadvertently rename (1).
+# CHECK-LABEL: name: test2
+# CHECK: INLINEASM &"", 32, 327690, def undef %0.sub0, 327690, def dead %1.sub1, 2147483657, undef %0.sub0(tied-def 3), 2147549193, %1.sub1(tied-def 5)
+name: test2
+body: |
+  bb.0:
+    undef %0.sub0:vreg_64 = IMPLICIT_DEF
+
+  bb.1:
+    undef %0.sub1:vreg_64 = V_ALIGNBIT_B32 %0.sub0:vreg_64, %0.sub0:vreg_64, 16, implicit $exec
+    INLINEASM &"", 32, 327690, def undef %0.sub0:vreg_64, 327690, def %0.sub1:vreg_64, 2147483657, undef %0.sub0:vreg_64(tied-def 3), 2147549193, %0.sub1:vreg_64(tied-def 5)
+    S_BRANCH %bb.1
+
+...
Index: lib/CodeGen/RenameIndependentSubregs.cpp
===================================================================
--- lib/CodeGen/RenameIndependentSubregs.cpp
+++ lib/CodeGen/RenameIndependentSubregs.cpp
@@ -219,7 +219,8 @@
     if (!MO.isDef() && !MO.readsReg())
       continue;
 
-    SlotIndex Pos = LIS->getInstructionIndex(*MO.getParent());
+    auto *MI = MO.getParent();
+    SlotIndex Pos = LIS->getInstructionIndex(*MI);
     Pos = MO.isDef() ? Pos.getRegSlot(MO.isEarlyClobber())
                      : Pos.getBaseIndex();
     unsigned SubRegIdx = MO.getSubReg();
@@ -245,11 +246,14 @@
     MO.setReg(VReg);
 
     if (MO.isTied() && Reg != VReg) {
-      /// Undef use operands are not tracked in the equivalence class but need
-      /// to be update if they are tied.
-      MO.getParent()->substituteRegister(Reg, VReg, 0, TRI);
-
-      // substituteRegister breaks the iterator, so restart.
+      /// Undef use operands are not tracked in the equivalence class,
+      /// but need to be updated if they are tied; take care to only
+      /// update the tied operand.
+      unsigned OperandNo = MI->getOperandNo(&MO);
+      unsigned TiedIdx = MI->findTiedOperandIdx(OperandNo);
+      MI->getOperand(TiedIdx).setReg(VReg);
+
+      // above substitution breaks the iterator, so restart.
       I = MRI->reg_nodbg_begin(Reg);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49052.154484.patch
Type: text/x-patch
Size: 2688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180707/ebc18905/attachment.bin>


More information about the llvm-commits mailing list