[llvm] [InstrRef] Preserve debug instr num in aarch64-ldst-opt. (PR #136009)
Jeremy Morse via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 25 08:08:54 PDT 2025
================
@@ -1227,6 +1249,79 @@ AArch64LoadStoreOpt::mergePairedInsns(MachineBasicBlock::iterator I,
.addImm(0)
.addImm(31);
(void)MIBSXTW;
+
+ // In the case of a sign-extend, where we have something like:
+ // debugValueSubstitutions:[]
+ // $w1 = LDRWui $x0, 1, debug-instr-number 1
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
+ // $x0 = LDRSWui $x0, 0, debug-instr-number 2
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
+
+ // It will be converted to:
+ // debugValueSubstitutions:[]
+ // $w0, $w1 = LDPWi $x0, 0
+ // $w0 = KILL $w0, implicit-def $x0
+ // $x0 = SBFMXri $x0, 0, 31
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
+
+ // $x0 is where the final value is stored, so the sign extend (SBFMXri)
+ // instruction contains the final value we care about we give it a new
+ // debug-instr-number 3. Whereas, $w1 contains the final value that we care
+ // about, therefore the LDP instruction is also given a new
+ // debug-instr-number 4. We have to add these subsitutions to the
+ // debugValueSubstitutions table. However, we also have to ensure that the
+ // OpIndex that pointed to debug-instr-number 1 gets updated to 1, because
+ // $w1 is the second operand of the LDP instruction.
+
+ // We want the final result to look like:
+ // debugValueSubstitutions:
+ // - { srcinst: 1, srcop: 0, dstinst: 4, dstop: 1, subreg: 0 }
+ // - { srcinst: 2, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
+ // $w0, $w1 = LDPWi $x0, 0, debug-instr-number 4
+ // $w0 = KILL $w0, implicit-def $x0
+ // $x0 = SBFMXri $x0, 0, 31, debug-instr-number 3
+ // DBG_INSTR_REF !7, dbg-instr-ref(1, 0), debug-location !9
+ // DBG_INSTR_REF !8, dbg-instr-ref(2, 0), debug-location !9
----------------
jmorse wrote:
Purely as a space saving suggestion, consider replacing the earlier paragraph of example output with this, and then explaining what the substitutions mean. IMHO (YMMV) it's easier for future readers to see the example correct-output first then reason about it. (This is very much a style suggestion, feel free to ignore)
https://github.com/llvm/llvm-project/pull/136009
More information about the llvm-commits
mailing list