Index: llvm/lib/Analysis/InstructionSimplify.cpp =================================================================== --- llvm/lib/Analysis/InstructionSimplify.cpp +++ llvm/lib/Analysis/InstructionSimplify.cpp @@ -4135,9 +4135,11 @@ // one element is undef, choose the defined element as the safe result. if (TEltC == FEltC) NewC.push_back(TEltC); - else if (isa(TEltC)) + else if (isa(TEltC) && + isGuaranteedNotToBeUndefOrPoison(FEltC)) NewC.push_back(FEltC); - else if (isa(FEltC)) + else if (isa(FEltC) && + isGuaranteedNotToBeUndefOrPoison(TEltC)) NewC.push_back(TEltC); else break; Index: llvm/test/Transforms/InstSimplify/select.ll =================================================================== --- llvm/test/Transforms/InstSimplify/select.ll +++ llvm/test/Transforms/InstSimplify/select.ll @@ -848,3 +848,17 @@ %s = select i1 %cond, i32 undef, i32 %xf ret i32 %s } + +@g = external global i32, align 1 + +; Make sure we don't fold partial undef vectors when constexprs are involved. +; We would need to prove the constexpr doesn't result in poison which we aren't +; equiped to do yet. +define <2 x i32> @false_undef_true_constextpr_vec(i1 %cond) { +; CHECK-LABEL: @false_undef_true_constextpr_vec( +; CHECK-NEXT: [[S:%.*]] = select i1 [[COND:%.*]], <2 x i32> , <2 x i32> +; CHECK-NEXT: ret <2 x i32> [[S]] +; + %s = select i1 %cond, <2 x i32> , <2 x i32> + ret <2 x i32> %s +}