diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -4136,7 +4136,8 @@ // Deal with partial undef vector constants: select ?, VecC, VecC' --> VecC'' Constant *TrueC, *FalseC; - if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) && + if (isa(TrueVal->getType()) && + match(TrueVal, m_Constant(TrueC)) && match(FalseVal, m_Constant(FalseC))) { unsigned NumElts = cast(TrueC->getType())->getNumElements(); diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll --- a/llvm/test/Transforms/InstSimplify/select.ll +++ b/llvm/test/Transforms/InstSimplify/select.ll @@ -957,3 +957,14 @@ ret i32 %r1.sroa.0.1 } declare i32 @llvm.cttz.i32(i32, i1 immarg) + +; Partial undef scalable vectors should be ignored. +define @ignore_scalable_undef( %cond) { +; CHECK-LABEL: @ignore_scalable_undef( +; CHECK-NEXT: [[S:%.*]] = select [[COND:%.*]], undef, insertelement ( undef, i1 true, i32 0) +; CHECK-NEXT: ret [[S]] +; + %vec = insertelement undef, i1 true, i32 0 + %s = select %cond, undef, %vec + ret %s +}