[llvm] r247229 - AMDGPU/SI: Fix creating v_mov_b32s without exec uses

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 18:06:06 PDT 2015


Author: arsenm
Date: Wed Sep  9 20:06:06 2015
New Revision: 247229

URL: http://llvm.org/viewvc/llvm-project?rev=247229&view=rev
Log:
AMDGPU/SI: Fix creating v_mov_b32s without exec uses

This will be caught by existing tests with a
verifier check to be added in a future commit.

Modified:
    llvm/trunk/lib/Target/AMDGPU/SIFoldOperands.cpp

Modified: llvm/trunk/lib/Target/AMDGPU/SIFoldOperands.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIFoldOperands.cpp?rev=247229&r1=247228&r2=247229&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIFoldOperands.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIFoldOperands.cpp Wed Sep  9 20:06:06 2015
@@ -189,6 +189,7 @@ static bool tryAddToFoldList(std::vector
 static void foldOperand(MachineOperand &OpToFold, MachineInstr *UseMI,
                         unsigned UseOpIdx,
                         std::vector<FoldCandidate> &FoldList,
+                        SmallVectorImpl<MachineInstr *> &CopiesToReplace,
                         const SIInstrInfo *TII, const SIRegisterInfo &TRI,
                         MachineRegisterInfo &MRI) {
   const MachineOperand &UseOp = UseMI->getOperand(UseOpIdx);
@@ -242,6 +243,7 @@ static void foldOperand(MachineOperand &
         return;
 
       UseMI->setDesc(TII->get(MovOp));
+      CopiesToReplace.push_back(UseMI);
     }
   }
 
@@ -261,7 +263,7 @@ static void foldOperand(MachineOperand &
         continue;
 
       foldOperand(OpToFold, RSUseMI, RSUse.getOperandNo(), FoldList,
-                  TII, TRI, MRI);
+                  CopiesToReplace, TII, TRI, MRI);
     }
     return;
   }
@@ -328,6 +330,12 @@ bool SIFoldOperands::runOnMachineFunctio
            OpToFold.getSubReg()))
         continue;
 
+
+      // We need mutate the operands of new mov instructions to add implicit
+      // uses of EXEC, but adding them invalidates the use_iterator, so defer
+      // this.
+      SmallVector<MachineInstr *, 4> CopiesToReplace;
+
       std::vector<FoldCandidate> FoldList;
       for (MachineRegisterInfo::use_iterator
            Use = MRI.use_begin(MI.getOperand(0).getReg()), E = MRI.use_end();
@@ -336,9 +344,13 @@ bool SIFoldOperands::runOnMachineFunctio
         MachineInstr *UseMI = Use->getParent();
 
         foldOperand(OpToFold, UseMI, Use.getOperandNo(), FoldList,
-                    TII, TRI, MRI);
+                    CopiesToReplace, TII, TRI, MRI);
       }
 
+      // Make sure we add EXEC uses to any new v_mov instructions created.
+      for (MachineInstr *Copy : CopiesToReplace)
+        Copy->addImplicitDefUseOperands(MF);
+
       for (FoldCandidate &Fold : FoldList) {
         if (updateOperand(Fold, TRI)) {
           // Clear kill flags.




More information about the llvm-commits mailing list