Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp =================================================================== --- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6631,10 +6631,9 @@ Value *RHS, const Twine &Name, Instruction *I) { Value *Op = createOp(Builder, RdxKind, LHS, RHS, Name); if (RecurrenceDescriptor::isIntMinMaxRecurrenceKind(RdxKind)) { - if (auto *Sel = dyn_cast(Op)) { - propagateIRFlags(Sel->getCondition(), - cast(I)->getCondition()); - } + if (auto *Sel = dyn_cast(Op)) + if (auto *SelI = dyn_cast(I)) + propagateIRFlags(Sel->getCondition(), SelI->getCondition()); } propagateIRFlags(Op, I); return Op; Index: llvm/test/Transforms/SLPVectorizer/slp-umax-rdx-crash.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/SLPVectorizer/slp-umax-rdx-crash.ll @@ -0,0 +1,35 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -slp-vectorizer -S < %s | FileCheck %s + +declare i32 @llvm.smin.i32(i32, i32) +declare i32 @llvm.umin.i32(i32, i32) + +; Given LLVM IR caused crash in SLP. +define void @test() { +; CHECK-LABEL: @test( +; CHECK-NEXT: entry: +; CHECK-NEXT: [[TMP0:%.*]] = call <4 x i32> @llvm.smin.v4i32(<4 x i32> undef, <4 x i32> ) +; CHECK-NEXT: [[TMP1:%.*]] = sub nsw <4 x i32> undef, [[TMP0]] +; CHECK-NEXT: [[TMP2:%.*]] = call i32 @llvm.vector.reduce.umin.v4i32(<4 x i32> [[TMP1]]) +; CHECK-NEXT: [[OP_EXTRA:%.*]] = icmp ult i32 [[TMP2]], 77 +; CHECK-NEXT: [[OP_EXTRA1:%.*]] = select i1 [[OP_EXTRA]], i32 [[TMP2]], i32 77 +; CHECK-NEXT: [[E:%.*]] = icmp ugt i32 [[OP_EXTRA1]], 1 +; CHECK-NEXT: ret void +; +entry: + %smin0 = call i32 @llvm.smin.i32(i32 undef, i32 0) + %smin1 = call i32 @llvm.smin.i32(i32 undef, i32 1) + %smin2 = call i32 @llvm.smin.i32(i32 undef, i32 2) + %smin3 = call i32 @llvm.smin.i32(i32 undef, i32 3) + %a = sub nsw i32 undef, %smin0 + %b = sub nsw i32 undef, %smin1 + %c = sub nsw i32 undef, %smin2 + %d = sub nsw i32 undef, %smin3 + %umin0 = call i32 @llvm.umin.i32(i32 %d, i32 %c) + %umin1 = call i32 @llvm.umin.i32(i32 %umin0, i32 %b) + %umin2 = call i32 @llvm.umin.i32(i32 %umin1, i32 %a) + %umin3 = call i32 @llvm.umin.i32(i32 %umin2, i32 77) + %e = icmp ugt i32 %umin3, 1 + ret void +} +