[PATCH] D83440: [InstSimplify] Re-enable select ?, undef, X -> X transform when X is provably not poison
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 11:08:22 PDT 2020
craig.topper updated this revision to Diff 276782.
craig.topper added a comment.
Use CxtI and DT if they are passed correctly in the SimplifyQuery
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D83440/new/
https://reviews.llvm.org/D83440
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/select.ll
Index: llvm/test/Transforms/InstSimplify/select.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/select.ll
+++ llvm/test/Transforms/InstSimplify/select.ll
@@ -794,8 +794,7 @@
; These can be folded because the other value is guaranteed not to be poison.
define i32 @false_undef_true_constant(i1 %cond) {
; CHECK-LABEL: @false_undef_true_constant(
-; CHECK-NEXT: [[S:%.*]] = select i1 [[COND:%.*]], i32 10, i32 undef
-; CHECK-NEXT: ret i32 [[S]]
+; CHECK-NEXT: ret i32 10
;
%s = select i1 %cond, i32 10, i32 undef
ret i32 %s
@@ -803,8 +802,7 @@
define i32 @true_undef_false_constant(i1 %cond) {
; CHECK-LABEL: @true_undef_false_constant(
-; CHECK-NEXT: [[S:%.*]] = select i1 [[COND:%.*]], i32 undef, i32 20
-; CHECK-NEXT: ret i32 [[S]]
+; CHECK-NEXT: ret i32 20
;
%s = select i1 %cond, i32 undef, i32 20
ret i32 %s
@@ -830,8 +828,7 @@
define i32 @false_undef_true_freeze(i1 %cond, i32 %x) {
; CHECK-LABEL: @false_undef_true_freeze(
; CHECK-NEXT: [[XF:%.*]] = freeze i32 [[X:%.*]]
-; CHECK-NEXT: [[S:%.*]] = select i1 [[COND:%.*]], i32 [[XF]], i32 undef
-; CHECK-NEXT: ret i32 [[S]]
+; CHECK-NEXT: ret i32 [[XF]]
;
%xf = freeze i32 %x
%s = select i1 %cond, i32 %xf, i32 undef
@@ -841,8 +838,7 @@
define i32 @false_undef_false_freeze(i1 %cond, i32 %x) {
; CHECK-LABEL: @false_undef_false_freeze(
; CHECK-NEXT: [[XF:%.*]] = freeze i32 [[X:%.*]]
-; CHECK-NEXT: [[S:%.*]] = select i1 [[COND:%.*]], i32 undef, i32 [[XF]]
-; CHECK-NEXT: ret i32 [[S]]
+; CHECK-NEXT: ret i32 [[XF]]
;
%xf = freeze i32 %x
%s = select i1 %cond, i32 undef, i32 %xf
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -4118,6 +4118,17 @@
if (TrueVal == FalseVal)
return TrueVal;
+ // If the true or false value is undef, we can fold to the other value as
+ // long as the other value isn't poison.
+ // select ?, undef, X -> X
+ if (isa<UndefValue>(TrueVal) &&
+ isGuaranteedNotToBeUndefOrPoison(FalseVal, Q.CxtI, Q.DT))
+ return FalseVal;
+ // select ?, X, undef -> X
+ if (isa<UndefValue>(FalseVal) &&
+ isGuaranteedNotToBeUndefOrPoison(TrueVal, Q.CxtI, Q.DT))
+ return TrueVal;
+
// Deal with partial undef vector constants: select ?, VecC, VecC' --> VecC''
Constant *TrueC, *FalseC;
if (TrueVal->getType()->isVectorTy() && match(TrueVal, m_Constant(TrueC)) &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83440.276782.patch
Type: text/x-patch
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200709/42ad9f40/attachment.bin>
More information about the llvm-commits
mailing list