Index: llvm/lib/IR/Instructions.cpp =================================================================== --- llvm/lib/IR/Instructions.cpp +++ llvm/lib/IR/Instructions.cpp @@ -2053,8 +2053,8 @@ if (UsesLHS && UsesRHS) return false; } - assert((UsesLHS ^ UsesRHS) && "Should have selected from exactly 1 source"); - return true; + // Allow for degenerate case: completely undef mask means neither source is used. + return UsesLHS || UsesRHS; } bool ShuffleVectorInst::isSingleSourceMask(ArrayRef Mask) { @@ -2182,6 +2182,8 @@ } bool ShuffleVectorInst::isIdentityWithPadding() const { + if (isa(Op<2>())) + return false; int NumOpElts = cast(Op<0>()->getType())->getNumElements(); int NumMaskElts = cast(getType())->getNumElements(); if (NumMaskElts <= NumOpElts) @@ -2201,6 +2203,8 @@ } bool ShuffleVectorInst::isIdentityWithExtract() const { + if (isa(Op<2>())) + return false; int NumOpElts = cast(Op<0>()->getType())->getNumElements(); int NumMaskElts = getType()->getNumElements(); if (NumMaskElts >= NumOpElts) @@ -2211,7 +2215,8 @@ bool ShuffleVectorInst::isConcat() const { // Vector concatenation is differentiated from identity with padding. - if (isa(Op<0>()) || isa(Op<1>())) + if (isa(Op<0>()) || isa(Op<1>()) || + isa(Op<2>())) return false; int NumOpElts = cast(Op<0>()->getType())->getNumElements(); Index: llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll =================================================================== --- /dev/null +++ llvm/test/Transforms/CodeGenPrepare/X86/cgp_shuffle_crash.ll @@ -0,0 +1,23 @@ +; RUN: opt -codegenprepare -S %s | FileCheck %s + +target triple = "x86_64-unknown-linux-gnu" + +; CHECK-LABEL: shuffle_one_source + +define void @shuffle_one_source() { +BB: + %Shuff7 = shufflevector <2 x i8> zeroinitializer, <2 x i8> zeroinitializer, <2 x i32> undef + br label %CF + +CF: ; preds = %CF, %BB + %Cmp82 = icmp slt i32 480483, undef + br i1 undef, label %CF, label %CF242 + +CF242: ; preds = %CF + %B109 = mul <2 x i8> undef, %Shuff7 + br label %CF245 + +CF245: ; preds = %CF245, %CF242 + %Sl187 = select i1 %Cmp82, <2 x i8> %B109, <2 x i8> undef + br label %CF245 +}