[all-commits] [llvm/llvm-project] 9b8c96: [InstrRef] Preserve debug instr num in aarch64-lds...

Shubham Sandeep Rastogi via All-commits all-commits at lists.llvm.org
Wed Apr 30 14:17:43 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9b8c96a040ae6b76bb73690acfc5bea85aaa51d4
      https://github.com/llvm/llvm-project/commit/9b8c96a040ae6b76bb73690acfc5bea85aaa51d4
  Author: Shubham Sandeep Rastogi <srastogi22 at apple.com>
  Date:   2025-04-30 (Wed, 30 Apr 2025)

  Changed paths:
    M llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp
    A llvm/test/CodeGen/AArch64/aarch64-ldst-opt-instr-ref.mir

  Log Message:
  -----------
  [InstrRef] Preserve debug instr num in aarch64-ldst-opt. (#136009)

The aarch64-ldst-opt pass tries to merge two load instructions
(LDR*) to a load pair instruction (LDP*).

When merging the instructions, there is a case where one of the 
loads would have to also be sign extended. In either case, 
(sign extend or not), the pass needs to preserve the debug-instr-number
from the original loads to the load pair instruction to make sure debug
info
isn't lost in the case where instruction referencing is being used.

For example:

We can have something like this:

```
debugValueSubstitutions:[]
$x1 = LDRXui $x0, 1, debug-instr-number 1
DBG_INSTR_REF !13, dbg-instr-ref(1, 0), debug-location !11
$x0 = LDRXui killed $x0, 0, debug-instr-number 2
DBG_INSTR_REF !14, dbg-instr-ref(2, 0), debug-location !11
```

This would be changed to:

```
debugValueSubstitutions: []
$x0, $x1 = LDPXi $x0, 0
DBG_INSTR_REF !12, dbg-instr-ref(1, 0), debug-location !14
DBG_INSTR_REF !13, dbg-instr-ref(2, 0), debug-location !14
```

In this case, we need to create a new debug instruction number
for the `LDP` instruction, we then need to add entries into the 
debugSubstitutions table to map the old instr-refs to the new ones.

After this patch, the result will be:
```
 debugValueSubstitutions:
 - { srcinst: 1, srcop: 0, dstinst: 3, dstop: 1, subreg: 0 }
 - { srcinst: 2, srcop: 0, dstinst: 3, dstop: 0, subreg: 0 }
 $x0, $x1 = LDPXi $x0, 0, debug-instr-number 3
 DBG_INSTR_REF !12, dbg-instr-ref(1, 0), debug-location !14
 DBG_INSTR_REF !12, dbg-instr-ref(2, 0), debug-location !14
```

However, this is not all, we also can have a case where there is a
sign-extend involved, let's look at the case:

```
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
```

This will become:

```
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.

The result after the patch looks 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
```


This patch addresses that problem.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list