[llvm] [SLP]Analyze widened reduction leaves in the narrow type (PR #216062)

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 05:56:45 PDT 2026


alexey-bataev wrote:

> `opt` crashes in the SLP vectorizer on the IR below.
> 
> ```llvm
> define amdgpu_kernel void @test() {
> entry:
>   br label %loop
> 
> loop:
>   %p3 = phi i8 [ %o3, %loop ], [ 0, %entry ]
>   %p2 = phi i8 [ %o2, %loop ], [ 0, %entry ]
>   %p1 = phi i8 [ %o1, %loop ], [ 0, %entry ]
>   %p0 = phi i8 [ %o0, %loop ], [ 0, %entry ]
>   %t0 = trunc i32 0 to i8
>   %o0 = or i8 %p0, %t0
>   %t1 = trunc i32 0 to i8
>   %o1 = or i8 %p1, %t1
>   %t2 = trunc i32 0 to i8
>   %o2 = or i8 %p2, %t2
>   %ld = load i32, ptr addrspace(3) null, align 1
>   %sh = lshr i32 %ld, 0
>   %t3 = trunc i32 %sh to i8
>   %o3 = or i8 %p3, %t3
>   %z3 = zext i8 %o3 to i32
>   %s3 = shl i32 %z3, 0
>   %z2 = zext i8 %o2 to i32
>   %a1 = or i32 %s3, %z2
>   %z1 = zext i8 %p1 to i32
>   %s1 = shl i32 %z1, 0
>   %a2 = or i32 %a1, %s1
>   %z0 = zext i8 %o0 to i32
>   %a3 = or i32 %a2, %z0
>   store i32 %a3, ptr addrspace(3) null, align 1
>   br label %loop
> }
> ```
> 
> Command:
> 
> ```
> opt -S -mtriple=amdgpu10.10-amd-amdhsa -passes=slp-vectorizer < test.ll
> ```
> 
> **Update**: Same IR fails with x86 too, so you can avoid building AMDGPU. Note that it doesn't fail with `-mcpu=x86-64` or `core2`.
> 
> ```
> opt -S -mtriple=x86_64-unknown-linux-gnu -mcpu=x86-64-v2 -passes=slp-vectorizer < test.ll
> ```
> 
> On current main ([5c70951](https://github.com/llvm/llvm-project/commit/5c7095190a97bba490470bb5f0cc18eae3357552)) this segfaults:
> 
> ```
> 2.	Running pass "slp-vectorizer" on function "test"
>  #4 generateKeySubkey(...)
>  #5 generateKeySubkey(...)
>  #6 (anonymous namespace)::HorizontalReduction::matchAssociativeReduction(...)
>  #7 llvm::SLPVectorizerPass::vectorizeHorReduction(...)
> ```
> 
> Bisected to this commit. I've tested with the fix in #218174 - unfortunately it doesn't help. @alexey-bataev please take a look. I can file an issue if you prefer.

Fixed in ce5d7430aab24cef7c9a3b786c26073001eecc4d

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


More information about the llvm-commits mailing list