Explorar o código

Fix SROA leaving some llvm.dbg.declare(undef) behind

Tristan Labelle %!s(int64=6) %!d(string=hai) anos
pai
achega
eac4d5c90b
Modificáronse 1 ficheiros con 13 adicións e 0 borrados
  1. 13 0
      lib/Transforms/Scalar/SROA.cpp

+ 13 - 0
lib/Transforms/Scalar/SROA.cpp

@@ -4446,6 +4446,17 @@ void SROA::deleteDeadInstructions(
     Instruction *I = DeadInsts.pop_back_val();
     DEBUG(dbgs() << "Deleting dead instruction: " << *I << "\n");
 
+    // HLSL Change Begins
+    // If the instruction is an alloca, find the possible dbg.declare connected
+    // to it, and remove it too. We must do this before calling RAUW or we will
+    // not be able to find it.
+    if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
+      DeletedAllocas.insert(AI);
+      if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(AI))
+        DbgDecl->eraseFromParent();
+    }
+    // HLSL Change Ends
+
     I->replaceAllUsesWith(UndefValue::get(I->getType()));
 
     for (Use &Operand : I->operands())
@@ -4456,11 +4467,13 @@ void SROA::deleteDeadInstructions(
           DeadInsts.insert(U);
       }
 
+#if 0 // HLSL Change - blocked moved before replaceAllUsesWith
     if (AllocaInst *AI = dyn_cast<AllocaInst>(I)) {
       DeletedAllocas.insert(AI);
       if (DbgDeclareInst *DbgDecl = FindAllocaDbgDeclare(AI))
         DbgDecl->eraseFromParent();
     }
+#endif // HLSL Change
 
     ++NumDeleted;
     I->eraseFromParent();