[llvm] [SelectionDAG] Salvage debuginfo when combining load and sext instrs. (PR #169779)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 8 11:56:25 PST 2025


================
@@ -14455,15 +14458,31 @@ static SDValue tryToFoldExtOfLoad(SelectionDAG &DAG, DAGCombiner &Combiner,
                                    LN0->getBasePtr(), N0.getValueType(),
                                    LN0->getMemOperand());
   Combiner.ExtendSetCCUses(SetCCs, N0, ExtLoad, ExtOpc);
+
   // If the load value is used only by N, replace it via CombineTo N.
-  bool NoReplaceTrunc = SDValue(LN0, 0).hasOneUse();
+  SDValue OldLoadVal(LN0, 0);
+  SDValue OldExtValue(N, 0);
+  bool NoReplaceTrunc = OldLoadVal.hasOneUse();
   Combiner.CombineTo(N, ExtLoad);
+
   if (NoReplaceTrunc) {
+    if (LN0->getHasDebugValue()) {
+      DAG.transferDbgValues(OldLoadVal, ExtLoad);
+      DAG.salvageDebugInfo(*ExtLoad.getNode());
+    }
+    if (N->getHasDebugValue())
+      DAG.transferDbgValues(OldExtValue, ExtLoad);
     DAG.ReplaceAllUsesOfValueWith(SDValue(LN0, 1), ExtLoad.getValue(1));
     Combiner.recursivelyDeleteUnusedNodes(LN0);
   } else {
     SDValue Trunc =
         DAG.getNode(ISD::TRUNCATE, SDLoc(N0), N0.getValueType(), ExtLoad);
+    if (LN0->getHasDebugValue()) {
+      DAG.transferDbgValues(OldLoadVal, Trunc);
+      DAG.salvageDebugInfo(*Trunc.getNode());
----------------
OCHyams wrote:

Please could we get test coverage for this path (if I've not missed it?)?

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


More information about the llvm-commits mailing list