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

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 02:59:07 PDT 2026


michaelselehov 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
```

On current main (5c7095190a97) this segfaults:

```
2. Running pass "slp-vectorizer" on function "test"
 #4 llvm::slpvectorizer::isVectorLikeInstWithConstOps(llvm::Value*)
 #5 generateKeySubkey(...)
 #6 generateKeySubkey(...)
 #7 (anonymous namespace)::HorizontalReduction::matchAssociativeReduction(...)
 #8 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.

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


More information about the llvm-commits mailing list