[llvm] [SROA] Improve select folding around casts (PR #222466)
Yaxun Liu via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 26 06:44:16 PDT 2026
yxsamliu wrote:
Thanks for the volatile-case fix. Here is the complete reproducer (16 lines):
```llvm
%struct.T = type { i32, i32 }
define i32 @test_select_fold_split_volatile(i1 %cond) {
%alloc0 = alloca %struct.T, align 8, addrspace(5)
%alloc1 = alloca %struct.T, align 8, addrspace(5)
store %struct.T { i32 0, i32 1 }, ptr addrspace(5) %alloc0
store %struct.T { i32 2, i32 3 }, ptr addrspace(5) %alloc1
%sel = select i1 %cond, ptr addrspace(5) %alloc0, ptr addrspace(5) %alloc1
%cast = addrspacecast ptr addrspace(5) %sel to ptr
%gep0 = getelementptr inbounds %struct.T, ptr %cast, i32 0, i32 0
%gep1 = getelementptr inbounds %struct.T, ptr %cast, i32 0, i32 1
%val1 = load volatile i32, ptr %gep0
%val2 = load volatile i32, ptr %gep1
%val3 = add i32 %val1, %val2
ret i32 %val3
}
```
I ran `opt -S -passes='default<O2>'` followed by `llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -O2`, using the same LLVM build with only `SROA.cpp` changed between revisions:
| Revision | Code bytes | VGPRs |
| --- | ---: | ---: |
| PR base (`4cc7b28c`) | 124 | 4 |
| Earlier PR head (`cf93fc85`) | 156 | 6 |
| Current head (`639ece04`) | 124 | 4 |
The current head preserves the single selected address and fixes this reproducer. Thanks!
https://github.com/llvm/llvm-project/pull/222466
More information about the llvm-commits
mailing list