[llvm] [DebugInfo][LoopLoadElim] Fix missing debug location updates (PR #91839)

J. Ryan Stinnett via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 05:58:05 PDT 2024


================
@@ -462,14 +466,20 @@ class LoadEliminationForLoop {
            "The type sizes should match!");
 
     Value *StoreValue = Cand.Store->getValueOperand();
-    if (LoadType != StoreType)
+    if (LoadType != StoreType) {
       StoreValue = CastInst::CreateBitOrPointerCast(StoreValue, LoadType,
                                                     "store_forward_cast",
                                                     Cand.Store->getIterator());
+      // Because it casts the old `load` value and is used by the new `phi`
+      // which replaces the old `load`, we give the `load`'s debug location
+      // to it.
+      cast<Instruction>(StoreValue)->setDebugLoc(Cand.Load->getDebugLoc());
+    }
 
     PHI->addIncoming(StoreValue, L->getLoopLatch());
 
     Cand.Load->replaceAllUsesWith(PHI);
+    PHI->setDebugLoc(Cand.Load->getDebugLoc());
----------------
jryans wrote:

Seems like enough of us have appeared and all concluded the same thing here, so I think we can leave this part as it is.

https://github.com/llvm/llvm-project/pull/91839


More information about the llvm-commits mailing list