llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[DAGCombine] Support extractelement of frozen load

Open nikic opened this issue 4 months ago • 2 comments

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 avatar Jul 23 '26 14:07 nikic

@nikic I am working on this

Xylecrack avatar Jul 27 '26 06:07 Xylecrack

Reference/Reproducer: https://godbolt.org/z/TY6Ee63rv

Xylecrack avatar Jul 28 '26 18:07 Xylecrack