[llvm] [ShrinkWrap] Modify shrink wrapping to accommodate functions terminated by no-return blocks (PR #167548)
Alex Bradbury via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 27 12:12:12 PST 2025
asb wrote:
I'll get a proper .ll reproducer tomorrow, but here's the .s diff for llvm-ar that is causing the issue:
```asm
--- ./tools/llvm-ar/CMakeFiles/llvm-ar.dir/llvm-ar.s 2025-11-27 19:02:12.188502784 +0000
+++ ../stage2.bad/./tools/llvm-ar/CMakeFiles/llvm-ar.dir/llvm-ar.s 2025-11-27 19:36:01.525297430 +00
00
@@ -6379,25 +6379,17 @@
_ZL11failIfErrorSt10error_codeN4llvm5TwineE: # @_ZL11failIfErrorSt10error_codeN4llvm5TwineE
.cfi_startproc
# %bb.0: # %entry
+ sext.w a0, a0
+ bnez a0, .LBB24_2
+# %bb.1: # %if.then
+ ret
+.LBB24_2: # %if.end
addi sp, sp, -304
.cfi_def_cfa_offset 304
sd ra, 296(sp) # 8-byte Folded Spill
sd s0, 288(sp) # 8-byte Folded Spill
.cfi_offset ra, -8
.cfi_offset s0, -16
- .cfi_remember_state
- sext.w a0, a0
- bnez a0, .LBB24_2
-# %bb.1: # %if.then
- ld ra, 296(sp) # 8-byte Folded Reload
- ld s0, 288(sp) # 8-byte Folded Reload
- .cfi_restore ra
- .cfi_restore s0
- addi sp, sp, 304
- .cfi_def_cfa_offset 0
- ret
-.LBB24_2: # %if.end
- .cfi_restore_state
sd a1, 8(sp) # 8-byte Folded Spill
sd a0, 16(sp) # 8-byte Folded Spill
addi a0, sp, 256
@@ -6405,6 +6397,12 @@
mv a1, a2
call _ZNK4llvm5Twine3strB5cxx11Ev
ld a0, 264(sp)
+ ld ra, 296(sp) # 8-byte Folded Reload
+ ld s0, 288(sp) # 8-byte Folded Reload
+ .cfi_restore ra
+ .cfi_restore s0
+ addi sp, sp, 304
+ .cfi_def_cfa_offset 0
bnez a0, .LBB24_4
# %bb.3: # %if.then2
ld a1, 8(sp) # 8-byte Folded Reload
```
At the end of `LBB24_2` in the 'bad' version, the stack is deallocated but then it's accessed in the fallthrough to ` # %bb.3:`
https://github.com/llvm/llvm-project/pull/167548
More information about the llvm-commits
mailing list