[PATCH] D23463: AMDGPU: Fix adding duplicate implicit exec uses

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 13:42:32 PDT 2016


arsenm created this revision.
arsenm added a reviewer: tstellarAMD.
arsenm added a subscriber: llvm-commits.
Herald added subscribers: kzhuravl, arsenm.

I'm not sure if this should be considered a bug in
copyImplicitOps or not, but implicit operands that are part
of the static instruction definition should not be copied.

https://reviews.llvm.org/D23463

Files:
  lib/Target/AMDGPU/SIShrinkInstructions.cpp

Index: lib/Target/AMDGPU/SIShrinkInstructions.cpp
===================================================================
--- lib/Target/AMDGPU/SIShrinkInstructions.cpp
+++ lib/Target/AMDGPU/SIShrinkInstructions.cpp
@@ -194,6 +194,20 @@
   return isInt<16>(Src.getImm()) && !TII->isInlineConstant(Src, 4);
 }
 
+/// Copy implicit register operands from specified instruction to this
+/// instruction that are not part of the instruction definition.
+static void copyExtraImplicitOps(MachineInstr &NewMI, MachineFunction &MF,
+                                 const MachineInstr &MI) {
+  for (unsigned i = MI.getDesc().getNumOperands() +
+         MI.getDesc().getNumImplicitUses() +
+         MI.getDesc().getNumImplicitDefs(), e = MI.getNumOperands();
+       i != e; ++i) {
+    const MachineOperand &MO = MI.getOperand(i);
+    if ((MO.isReg() && MO.isImplicit()) || MO.isRegMask())
+      NewMI.addOperand(MF, MO);
+  }
+}
+
 bool SIShrinkInstructions::runOnMachineFunction(MachineFunction &MF) {
   if (skipFunction(*MF.getFunction()))
     return false;
@@ -400,7 +414,7 @@
       ++NumInstructionsShrunk;
 
       // Copy extra operands not present in the instruction definition.
-      Inst32->copyImplicitOps(MF, MI);
+      copyExtraImplicitOps(*Inst32, MF, MI);
 
       MI.eraseFromParent();
       foldImmediates(*Inst32, TII, MRI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23463.67902.patch
Type: text/x-patch
Size: 1343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160812/6d0104f5/attachment.bin>


More information about the llvm-commits mailing list