[llvm] [SLP]Vectorize operand chains of non-vectorizable instructions (PR #194248)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri May 1 03:00:46 PDT 2026


alexey-bataev wrote:

> I ran scalar.ll through opt -passes=slp-vectorizer and it stays scalar. I attached expected.ll IR as I expected after SLP it would get it vectorized. Should we treat this as a gap worth fixing?
> 
> scalar.ll
> 
> ```
> ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
> ; RUN: opt -passes=slp-vectorizer -slp-inst-count-check=false -S -mcpu=gfx1250 -mtriple=amdgcn-amd-amdhsa -o - %s | FileCheck %s --check-prefixes GCN
> 
> define amdgpu_kernel void @kernel_alternate(ptr addrspace(1) %a, ptr addrspace(1) %b, ptr addrspace(1) %output) {
> ; GCN-LABEL: define amdgpu_kernel void @kernel_alternate(
> ; GCN-SAME: ptr addrspace(1) [[A:%.*]], ptr addrspace(1) [[B:%.*]], ptr addrspace(1) [[OUTPUT:%.*]]) #[[ATTR0:[0-9]+]] {
> ; GCN-NEXT:  [[ENTRY:.*:]]
> ; GCN-NEXT:    [[A0:%.*]] = load float, ptr addrspace(1) [[A]], align 4
> ; GCN-NEXT:    [[APTR1:%.*]] = getelementptr float, ptr addrspace(1) [[A]], i64 1
> ; GCN-NEXT:    [[A1:%.*]] = load float, ptr addrspace(1) [[APTR1]], align 4
> ; GCN-NEXT:    [[APTR2:%.*]] = getelementptr float, ptr addrspace(1) [[A]], i64 2
> ; GCN-NEXT:    [[A2:%.*]] = load float, ptr addrspace(1) [[APTR2]], align 4
> ; GCN-NEXT:    [[B0:%.*]] = load float, ptr addrspace(1) [[B]], align 4
> ; GCN-NEXT:    [[BPTR1:%.*]] = getelementptr float, ptr addrspace(1) [[B]], i64 1
> ; GCN-NEXT:    [[B1:%.*]] = load float, ptr addrspace(1) [[BPTR1]], align 4
> ; GCN-NEXT:    [[BPTR2:%.*]] = getelementptr float, ptr addrspace(1) [[B]], i64 2
> ; GCN-NEXT:    [[B2:%.*]] = load float, ptr addrspace(1) [[BPTR2]], align 4
> ; GCN-NEXT:    [[ADD0:%.*]] = fadd float [[A0]], [[B0]]
> ; GCN-NEXT:    [[SUB0:%.*]] = fsub float [[A0]], [[B0]]
> ; GCN-NEXT:    [[ADD1:%.*]] = fadd float [[A1]], [[B1]]
> ; GCN-NEXT:    [[SUB1:%.*]] = fsub float [[A1]], [[B1]]
> ; GCN-NEXT:    [[ADD2:%.*]] = fadd float [[A2]], [[B2]]
> ; GCN-NEXT:    [[SUB2:%.*]] = fsub float [[A2]], [[B2]]
> ; GCN-NEXT:    [[E0:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[ADD0]])
> ; GCN-NEXT:    [[E1:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[SUB0]])
> ; GCN-NEXT:    [[E2:%.*]] = call float @llvm.amdgcn.log.f32(float [[ADD1]])
> ; GCN-NEXT:    [[E3:%.*]] = call float @llvm.amdgcn.log.f32(float [[SUB1]])
> ; GCN-NEXT:    [[E4:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[ADD2]])
> ; GCN-NEXT:    [[E5:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[SUB2]])
> ; GCN-NEXT:    [[OPTR0:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 0
> ; GCN-NEXT:    [[OPTR1:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 1
> ; GCN-NEXT:    [[OPTR2:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 2
> ; GCN-NEXT:    [[OPTR3:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 3
> ; GCN-NEXT:    [[OPTR4:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 4
> ; GCN-NEXT:    [[OPTR5:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 5
> ; GCN-NEXT:    store float [[E0]], ptr addrspace(1) [[OPTR0]], align 4
> ; GCN-NEXT:    store float [[E1]], ptr addrspace(1) [[OPTR1]], align 4
> ; GCN-NEXT:    store float [[E2]], ptr addrspace(1) [[OPTR2]], align 4
> ; GCN-NEXT:    store float [[E3]], ptr addrspace(1) [[OPTR3]], align 4
> ; GCN-NEXT:    store float [[E4]], ptr addrspace(1) [[OPTR4]], align 4
> ; GCN-NEXT:    store float [[E5]], ptr addrspace(1) [[OPTR5]], align 4
> ; GCN-NEXT:    ret void
> ;
> entry:
>   %a0    = load float, ptr addrspace(1) %a, align 4
>   %aptr1 = getelementptr float, ptr addrspace(1) %a, i64 1
>   %a1    = load float, ptr addrspace(1) %aptr1, align 4
>   %aptr2 = getelementptr float, ptr addrspace(1) %a, i64 2
>   %a2    = load float, ptr addrspace(1) %aptr2, align 4
> 
>   %b0    = load float, ptr addrspace(1) %b, align 4
>   %bptr1 = getelementptr float, ptr addrspace(1) %b, i64 1
>   %b1    = load float, ptr addrspace(1) %bptr1, align 4
>   %bptr2 = getelementptr float, ptr addrspace(1) %b, i64 2
>   %b2    = load float, ptr addrspace(1) %bptr2, align 4
> 
>   %add0 = fadd float %a0, %b0
>   %sub0 = fsub float %a0, %b0
>   %add1 = fadd float %a1, %b1
>   %sub1 = fsub float %a1, %b1
>   %add2 = fadd float %a2, %b2
>   %sub2 = fsub float %a2, %b2
> 
>   %e0 = call float @llvm.amdgcn.exp2.f32(float %add0)
>   %e1 = call float @llvm.amdgcn.exp2.f32(float %sub0)
>   %e2 = call float @llvm.amdgcn.log.f32(float %add1)
>   %e3 = call float @llvm.amdgcn.log.f32(float %sub1)
>   %e4 = call float @llvm.amdgcn.exp2.f32(float %add2)
>   %e5 = call float @llvm.amdgcn.exp2.f32(float %sub2)
> 
>   %optr0 = getelementptr float, ptr addrspace(1) %output, i64 0
>   %optr1 = getelementptr float, ptr addrspace(1) %output, i64 1
>   %optr2 = getelementptr float, ptr addrspace(1) %output, i64 2
>   %optr3 = getelementptr float, ptr addrspace(1) %output, i64 3
>   %optr4 = getelementptr float, ptr addrspace(1) %output, i64 4
>   %optr5 = getelementptr float, ptr addrspace(1) %output, i64 5
> 
>   store float %e0, ptr addrspace(1) %optr0, align 4
>   store float %e1, ptr addrspace(1) %optr1, align 4
>   store float %e2, ptr addrspace(1) %optr2, align 4
>   store float %e3, ptr addrspace(1) %optr3, align 4
>   store float %e4, ptr addrspace(1) %optr4, align 4
>   store float %e5, ptr addrspace(1) %optr5, align 4
>   ret void
> }
> 
> declare float @llvm.amdgcn.exp2.f32(float)
> declare float @llvm.amdgcn.log.f32(float)
> ```
> 
> expected.ll
> 
> ```
> ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
> ; RUN: opt -passes=slp-vectorizer -slp-inst-count-check=false -S -mcpu=gfx1250 -mtriple=amdgcn-amd-amdhsa -o - %s | FileCheck %s --check-prefixes GCN
> 
> define amdgpu_kernel void @kernel_alternate(ptr addrspace(1) %a, ptr addrspace(1) %b, ptr addrspace(1) %output) {
> ; GCN-LABEL: define amdgpu_kernel void @kernel_alternate(
> ; GCN-SAME: ptr addrspace(1) [[A:%.*]], ptr addrspace(1) [[B:%.*]], ptr addrspace(1) [[OUTPUT:%.*]]) #[[ATTR0:[0-9]+]] {
> ; GCN-NEXT:  [[ENTRY:.*:]]
> ; GCN-NEXT:    [[APTR2:%.*]] = getelementptr float, ptr addrspace(1) [[A]], i64 2
> ; GCN-NEXT:    [[A2:%.*]] = load float, ptr addrspace(1) [[APTR2]], align 4
> ; GCN-NEXT:    [[BPTR2:%.*]] = getelementptr float, ptr addrspace(1) [[B]], i64 2
> ; GCN-NEXT:    [[B2:%.*]] = load float, ptr addrspace(1) [[BPTR2]], align 4
> ; GCN-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr addrspace(1) [[A]], align 4
> ; GCN-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr addrspace(1) [[B]], align 4
> ; GCN-NEXT:    [[TMP2:%.*]] = fadd <2 x float> [[TMP0]], [[TMP1]]
> ; GCN-NEXT:    [[TMP3:%.*]] = fsub <2 x float> [[TMP0]], [[TMP1]]
> ; GCN-NEXT:    [[ADD2:%.*]] = fadd float [[A2]], [[B2]]
> ; GCN-NEXT:    [[SUB2:%.*]] = fsub float [[A2]], [[B2]]
> ; GCN-NEXT:    [[ADD0:%.*]] = extractelement <2 x float> [[TMP2]], i32 0
> ; GCN-NEXT:    [[E0:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[ADD0]])
> ; GCN-NEXT:    [[SUB0:%.*]] = extractelement <2 x float> [[TMP3]], i32 0
> ; GCN-NEXT:    [[E1:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[SUB0]])
> ; GCN-NEXT:    [[ADD1:%.*]] = extractelement <2 x float> [[TMP2]], i32 1
> ; GCN-NEXT:    [[E2:%.*]] = call float @llvm.amdgcn.log.f32(float [[ADD1]])
> ; GCN-NEXT:    [[SUB1:%.*]] = extractelement <2 x float> [[TMP3]], i32 1
> ; GCN-NEXT:    [[E3:%.*]] = call float @llvm.amdgcn.log.f32(float [[SUB1]])
> ; GCN-NEXT:    [[E4:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[ADD2]])
> ; GCN-NEXT:    [[E5:%.*]] = call float @llvm.amdgcn.exp2.f32(float [[SUB2]])
> ; GCN-NEXT:    [[OPTR0:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 0
> ; GCN-NEXT:    [[OPTR1:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 1
> ; GCN-NEXT:    [[OPTR2:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 2
> ; GCN-NEXT:    [[OPTR3:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 3
> ; GCN-NEXT:    [[OPTR4:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 4
> ; GCN-NEXT:    [[OPTR5:%.*]] = getelementptr float, ptr addrspace(1) [[OUTPUT]], i64 5
> ; GCN-NEXT:    store float [[E0]], ptr addrspace(1) [[OPTR0]], align 4
> ; GCN-NEXT:    store float [[E1]], ptr addrspace(1) [[OPTR1]], align 4
> ; GCN-NEXT:    store float [[E2]], ptr addrspace(1) [[OPTR2]], align 4
> ; GCN-NEXT:    store float [[E3]], ptr addrspace(1) [[OPTR3]], align 4
> ; GCN-NEXT:    store float [[E4]], ptr addrspace(1) [[OPTR4]], align 4
> ; GCN-NEXT:    store float [[E5]], ptr addrspace(1) [[OPTR5]], align 4
> ; GCN-NEXT:    ret void
> ;
> entry:
>   %a0    = load float, ptr addrspace(1) %a, align 4
>   %aptr1 = getelementptr float, ptr addrspace(1) %a, i64 1
>   %a1    = load float, ptr addrspace(1) %aptr1, align 4
>   %aptr2 = getelementptr float, ptr addrspace(1) %a, i64 2
>   %a2    = load float, ptr addrspace(1) %aptr2, align 4
> 
>   %b0    = load float, ptr addrspace(1) %b, align 4
>   %bptr1 = getelementptr float, ptr addrspace(1) %b, i64 1
>   %b1    = load float, ptr addrspace(1) %bptr1, align 4
>   %bptr2 = getelementptr float, ptr addrspace(1) %b, i64 2
>   %b2    = load float, ptr addrspace(1) %bptr2, align 4
> 
>   %add0 = fadd float %a0, %b0
>   %sub0 = fsub float %a0, %b0
>   %add1 = fadd float %a1, %b1
>   %sub1 = fsub float %a1, %b1
>   %add2 = fadd float %a2, %b2
>   %sub2 = fsub float %a2, %b2
> 
>   %e0 = call float @llvm.amdgcn.exp2.f32(float %add0)
>   %e1 = call float @llvm.amdgcn.exp2.f32(float %sub0)
>   %e2 = call float @llvm.amdgcn.log.f32(float %add1)
>   %e3 = call float @llvm.amdgcn.log.f32(float %sub1)
>   %e4 = call float @llvm.amdgcn.exp2.f32(float %add2)
>   %e5 = call float @llvm.amdgcn.exp2.f32(float %sub2)
> 
>   %optr0 = getelementptr float, ptr addrspace(1) %output, i64 0
>   %optr1 = getelementptr float, ptr addrspace(1) %output, i64 1
>   %optr2 = getelementptr float, ptr addrspace(1) %output, i64 2
>   %optr3 = getelementptr float, ptr addrspace(1) %output, i64 3
>   %optr4 = getelementptr float, ptr addrspace(1) %output, i64 4
>   %optr5 = getelementptr float, ptr addrspace(1) %output, i64 5
> 
>   store float %e0, ptr addrspace(1) %optr0, align 4
>   store float %e1, ptr addrspace(1) %optr1, align 4
>   store float %e2, ptr addrspace(1) %optr2, align 4
>   store float %e3, ptr addrspace(1) %optr3, align 4
>   store float %e4, ptr addrspace(1) %optr4, align 4
>   store float %e5, ptr addrspace(1) %optr5, align 4
>   ret void
> }
> 
> declare float @llvm.amdgcn.exp2.f32(float)
> declare float @llvm.amdgcn.log.f32(float)
> ```

Looks like a cross-call vectorization, i.e. vectorization of the operands across different intrinsics calls. Can be added later, I think

https://github.com/llvm/llvm-project/pull/194248


More information about the llvm-commits mailing list