[llvm] 122b064 - [InstSimplify] Don't fold vectors of partial undef in SimplifySelectInst if the non-undef element value might produce poison
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 11:01:38 PDT 2020
Author: Craig Topper
Date: 2020-07-09T11:01:12-07:00
New Revision: 122b0640fc97202bacb630744dfc6da58f11af42
URL: https://github.com/llvm/llvm-project/commit/122b0640fc97202bacb630744dfc6da58f11af42
DIFF: https://github.com/llvm/llvm-project/commit/122b0640fc97202bacb630744dfc6da58f11af42.diff
LOG: [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
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/select.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 8cd5d2034586..277e2907fa04 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -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;
diff --git a/llvm/test/Transforms/InstSimplify/select.ll b/llvm/test/Transforms/InstSimplify/select.ll
index 0f43c8f61945..8b69badb32f3 100644
--- a/llvm/test/Transforms/InstSimplify/select.ll
+++ b/llvm/test/Transforms/InstSimplify/select.ll
@@ -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
}
+
+ at 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
+}
More information about the llvm-commits
mailing list