[llvm] [AMDGPU][NPM] Fix CFG invalidation detection in insertSimulatedTrap (PR #169290)
Prasoon Mishra via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 24 01:41:25 PST 2025
PrasoonMishra wrote:
This bug was discovered while enabling the NPM pipeline for AMDGPU. Without this patch, the existing test [trap-abis.ll](https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/AMDGPU/trap-abis.ll) fails under NPM.
The [`trap` function (lines 12-104)](https://github.com/llvm/llvm-project/blob/main/llvm/test/CodeGen/AMDGPU/trap-abis.ll#L12-L104) expects loop header comments:
```
define amdgpu_kernel void @trap(ptr addrspace(1) nocapture readonly %arg0) {
; HSA-TRAP-GFX1100-O0-NEXT: .LBB0_1: ; =>This Inner Loop Header: Depth=1
; HSA-TRAP-GFX1100-O0-NEXT: s_sethalt 5
; HSA-TRAP-GFX1100-O0-NEXT: s_branch .LBB0_1
store volatile i32 1, ptr addrspace(1) %arg0
call void @llvm.trap()
unreachable
store volatile i32 2, ptr addrspace(1) %arg0
ret void
}
Error signature:
# .---command stderr------------
# | /.../git/llvm-project/llvm/test/CodeGen/AMDGPU/trap-abis.ll:96:29: error: HSA-TRAP-GFX1100-O0-NEXT: expected string not found in input
# | ; HSA-TRAP-GFX1100-O0-NEXT: .LBB0_1: ; =>This Inner Loop Header: Depth=1
# | ^
# | <stdin>:23:21: note: scanning from here
# | s_mov_b32 m0, ttmp2
```
**Expected:** `.LBB0_1: ; =>This Inner Loop Header: Depth=1`
**Actual (without fix):** `.LBB0_1:` (missing loop header comment)
This happens only when using NPM pipeline because legacy pass manager conservatively recomputes analyses, so MachineLoopInfo is refreshed before AsmPrinter, masking the bug. NPM relies on accurate invalidation signals hence when insertSimulatedTrap incorrectly signals “no CFG change,” MachineLoopInfo remains stale, causing missing loop headers.
This fix resolves the following issue.
https://github.com/llvm/llvm-project/pull/169290
More information about the llvm-commits
mailing list