[InstSimplify] Don't fold vectors of partial undef in SimplifySelectInst if the non-undef element value might produce poison
We can't fold to the non-undef value unless we know it isn't poison. So check each element with isGuaranteedNotToBeUndefOrPoison. This currently rules out all constant expressions. Differential Revision: https://reviews.llvm.org/D83442
This commit is contained in:
@@ -4135,9 +4135,11 @@ static Value *SimplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
|
||||
// one element is undef, choose the defined element as the safe result.
|
||||
if (TEltC == FEltC)
|
||||
NewC.push_back(TEltC);
|
||||
else if (isa<UndefValue>(TEltC))
|
||||
else if (isa<UndefValue>(TEltC) &&
|
||||
isGuaranteedNotToBeUndefOrPoison(FEltC))
|
||||
NewC.push_back(FEltC);
|
||||
else if (isa<UndefValue>(FEltC))
|
||||
else if (isa<UndefValue>(FEltC) &&
|
||||
isGuaranteedNotToBeUndefOrPoison(TEltC))
|
||||
NewC.push_back(TEltC);
|
||||
else
|
||||
break;
|
||||
|
||||
@@ -848,3 +848,17 @@ define i32 @false_undef_false_freeze(i1 %cond, i32 %x) {
|
||||
%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> <i32 undef, i32 ptrtoint (i32* @g to i32)>, <2 x i32> <i32 ptrtoint (i32* @g to i32), i32 undef>
|
||||
; CHECK-NEXT: ret <2 x i32> [[S]]
|
||||
;
|
||||
%s = select i1 %cond, <2 x i32> <i32 undef, i32 ptrtoint (i32* @g to i32)>, <2 x i32> <i32 ptrtoint (i32* @g to i32), i32 undef>
|
||||
ret <2 x i32> %s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user