llvm-project
llvm-project copied to clipboard
[DAGCombine] Support extractelement of frozen load
define i32 @test(ptr addrspace(1) %p) {
%load = load <2 x i32>, ptr addrspace(1) %p
%freeze = freeze <2 x i32> %load
%extract = extractelement <2 x i32> %freeze, i64 0
ret i32 %extract
}
define i32 @test2(ptr addrspace(1) %p) {
%load = load <2 x i32>, ptr addrspace(1) %p
%extract = extractelement <2 x i32> %load, i64 0
ret i32 %extract
}
With -mtriple=amdgpu6.00 this produces buffer_load_dwordx2 in the first case and buffer_load_dword in the second. The first case could also be buffer_load_dword.
The relevant code is: https://github.com/llvm/llvm-project/blob/3cbb24bd5412a5ecea5a0e4d1603e0a38676432d/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp#L25897-L26000
The folds here should all support looking through a one-use freeze and then creating a new freeze around the scalarized load.
@nikic I am working on this
Reference/Reproducer: https://godbolt.org/z/TY6Ee63rv