diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2906,7 +2906,11 @@ case Instruction::ShuffleVector: { // Collect the minimum number of sign bits that are shared by every vector // element referenced by the shuffle. - auto *Shuf = cast(U); + auto *Shuf = dyn_cast(U); + if (!Shuf) { + // FIXME: Add support for shufflevector constant expressions. + return 1; + } APInt DemandedLHS, DemandedRHS; // For undef elements, we don't know anything about the common state of // the shuffle result. diff --git a/llvm/test/Transforms/InstCombine/nsw.ll b/llvm/test/Transforms/InstCombine/nsw.ll --- a/llvm/test/Transforms/InstCombine/nsw.ll +++ b/llvm/test/Transforms/InstCombine/nsw.ll @@ -128,3 +128,15 @@ ret <3 x i32> %t3 } +; Make sure we don't crash on a ConstantExpr shufflevector +define @mul_nuw_nsw_shuffle_constant_expr( %z) { +; CHECK-LABEL: @mul_nuw_nsw_shuffle_constant_expr( +; CHECK-NEXT: [[XX:%.*]] = zext [[Z:%.*]] to +; CHECK-NEXT: [[T3:%.*]] = mul [[XX]], shufflevector ( insertelement ( undef, i64 3, i32 0), zeroinitializer, zeroinitializer) +; CHECK-NEXT: ret [[T3]] +; + %xx = zext %z to + %shuf = shufflevector insertelement ( undef, i64 3, i32 0), zeroinitializer, zeroinitializer + %t3 = mul %shuf, %xx + ret %t3 +}