[llvm] f493548 - Revert "[InstCombine] Add simplification of two logical and/ors"
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 9 12:54:08 PST 2021
Author: Juneyoung Lee
Date: 2021-03-10T05:48:31+09:00
New Revision: f49354838e526671e616d16199ebdee653b9f6fa
URL: https://github.com/llvm/llvm-project/commit/f49354838e526671e616d16199ebdee653b9f6fa
DIFF: https://github.com/llvm/llvm-project/commit/f49354838e526671e616d16199ebdee653b9f6fa.diff
LOG: Revert "[InstCombine] Add simplification of two logical and/ors"
This reverts commit 07c3b97e184d5bd828b8a680cdce46e73f3db9fc due to a reported failure in two-stage build.
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 0f7575fc104e..f7b656d88dfa 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -68,8 +68,6 @@ static Value *SimplifyCastInst(unsigned, Value *, Type *,
const SimplifyQuery &, unsigned);
static Value *SimplifyGEPInst(Type *, ArrayRef<Value *>, const SimplifyQuery &,
unsigned);
-static Value *SimplifySelectInst(Value *, Value *, Value *,
- const SimplifyQuery &, unsigned);
static Value *foldSelectWithBinaryOp(Value *Cond, Value *TrueVal,
Value *FalseVal) {
@@ -3994,17 +3992,6 @@ static Value *SimplifyWithOpReplaced(Value *V, Value *Op, Value *RepOp,
}
}
- // Same for Selects.
- if (auto *SI = dyn_cast<SelectInst>(I)) {
- if (MaxRecurse) {
- SmallVector<Value *, 3> NewOps(3);
- transform(SI->operands(), NewOps.begin(),
- [&](Value *V) { return V == Op ? RepOp : V; });
- return PreventSelfSimplify(SimplifySelectInst(
- NewOps[0], NewOps[1], NewOps[2], Q, MaxRecurse - 1));
- }
- }
-
// TODO: We could hand off more cases to instsimplify here.
// If all operands are constant after substituting Op for RepOp then we can
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 7d7a52b4de31..6ad10f90d7ca 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2600,50 +2600,34 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
return BinaryOperator::CreateAnd(CondVal, TrueVal);
}
- auto *One = ConstantInt::getTrue(SelType);
- auto *Zero = ConstantInt::getFalse(SelType);
-
// select a, false, b -> select !a, b, false
if (match(TrueVal, m_Zero())) {
Value *NotCond = Builder.CreateNot(CondVal, "not." + CondVal->getName());
- return SelectInst::Create(NotCond, FalseVal, Zero);
+ return SelectInst::Create(NotCond, FalseVal,
+ ConstantInt::getFalse(SelType));
}
// select a, b, true -> select !a, true, b
if (match(FalseVal, m_One())) {
Value *NotCond = Builder.CreateNot(CondVal, "not." + CondVal->getName());
- return SelectInst::Create(NotCond, One, TrueVal);
+ return SelectInst::Create(NotCond, ConstantInt::getTrue(SelType),
+ TrueVal);
}
// select a, a, b -> select a, true, b
if (CondVal == TrueVal)
- return replaceOperand(SI, 1, One);
+ return replaceOperand(SI, 1, ConstantInt::getTrue(SelType));
// select a, b, a -> select a, b, false
if (CondVal == FalseVal)
- return replaceOperand(SI, 2, Zero);
+ return replaceOperand(SI, 2, ConstantInt::getFalse(SelType));
// select a, !a, b -> select !a, b, false
if (match(TrueVal, m_Not(m_Specific(CondVal))))
- return SelectInst::Create(TrueVal, FalseVal, Zero);
+ return SelectInst::Create(TrueVal, FalseVal,
+ ConstantInt::getFalse(SelType));
// select a, b, !a -> select !a, true, b
if (match(FalseVal, m_Not(m_Specific(CondVal))))
- return SelectInst::Create(FalseVal, One, TrueVal);
-
- Value *A, *B;
- // select (select a, true, b), true, b -> select a, true, b
- if (match(CondVal, m_Select(m_Value(A), m_One(), m_Value(B))) &&
- match(TrueVal, m_One()) && match(FalseVal, m_Specific(B)))
- return replaceOperand(SI, 0, A);
- // select (select a, b, false), b, false -> select a, b, false
- if (match(CondVal, m_Select(m_Value(A), m_Value(B), m_Zero())) &&
- match(TrueVal, m_Specific(B)) && match(FalseVal, m_Zero()))
- return replaceOperand(SI, 0, A);
-
- if (Value *S = SimplifyWithOpReplaced(TrueVal, CondVal, One, SQ,
- /* AllowRefinement */ true))
- return replaceOperand(SI, 1, S);
- if (Value *S = SimplifyWithOpReplaced(FalseVal, CondVal, Zero, SQ,
- /* AllowRefinement */ true))
- return replaceOperand(SI, 2, S);
+ return SelectInst::Create(FalseVal, ConstantInt::getTrue(SelType),
+ TrueVal);
}
// Selecting between two integer or vector splat integer constants?
diff --git a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
index f86febaf95ee..83275ec21c3c 100644
--- a/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
+++ b/llvm/test/Transforms/InstCombine/select-safe-bool-transforms.ll
@@ -18,7 +18,8 @@ define i1 @land_land_left1(i1 %A, i1 %B) {
}
define i1 @land_land_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_land_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 [[A]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
%c = select i1 %B, i1 %A, i1 false
@@ -180,7 +181,8 @@ define i1 @lor_lor_left1(i1 %A, i1 %B) {
}
define i1 @lor_lor_left2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_lor_left2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[C]], i1 true, i1 [[A]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = select i1 %B, i1 true, i1 %A
@@ -260,8 +262,8 @@ define i1 @land_land_right1(i1 %A, i1 %B) {
}
define i1 @land_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
-; CHECK-NEXT: ret i1 [[RES]]
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%c = select i1 %B, i1 %A, i1 false
%res = select i1 %A, i1 %c, i1 false
@@ -299,7 +301,9 @@ define i1 @land_lor_right1(i1 %A, i1 %B) {
}
define i1 @land_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @land_lor_right2(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 [[A:%.*]], i1 false
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = select i1 %B, i1 %A, i1 false
%res = select i1 %A, i1 true, i1 %c
@@ -329,7 +333,8 @@ define i1 @land_bor_right2(i1 %A, i1 %B) {
; A land (A band B)
define i1 @band_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %A, %B
@@ -338,7 +343,8 @@ define i1 @band_land_right1(i1 %A, i1 %B) {
}
define i1 @band_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_land_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 [[B:%.*]], i1 false
+; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %B, %A
@@ -349,7 +355,9 @@ define i1 @band_land_right2(i1 %A, i1 %B) {
; A lor (A band B)
define i1 @band_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_right1(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %A, %B
%res = select i1 %A, i1 true, i1 %c
@@ -357,7 +365,9 @@ define i1 @band_lor_right1(i1 %A, i1 %B) {
}
define i1 @band_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @band_lor_right2(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = and i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = and i1 %B, %A
%res = select i1 %A, i1 true, i1 %c
@@ -375,7 +385,9 @@ define i1 @lor_land_right1(i1 %A, i1 %B) {
}
define i1 @lor_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_land_right2(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = select i1 [[B:%.*]], i1 true, i1 [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = select i1 %B, i1 true, i1 %A
%res = select i1 %A, i1 %c, i1 false
@@ -414,8 +426,8 @@ define i1 @lor_lor_right1(i1 %A, i1 %B) {
}
define i1 @lor_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @lor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
-; CHECK-NEXT: ret i1 [[RES]]
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: ret i1 [[TMP1]]
;
%c = select i1 %B, i1 true, i1 %A
%res = select i1 %A, i1 true, i1 %c
@@ -445,7 +457,9 @@ define i1 @lor_bor_right2(i1 %A, i1 %B) {
; A land (A bor B)
define i1 @bor_land_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_right1(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %A, %B
%res = select i1 %A, i1 %c, i1 false
@@ -453,7 +467,9 @@ define i1 @bor_land_right1(i1 %A, i1 %B) {
}
define i1 @bor_land_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_land_right2(
-; CHECK-NEXT: ret i1 [[A:%.*]]
+; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 [[C]], i1 false
+; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %B, %A
%res = select i1 %A, i1 %c, i1 false
@@ -463,7 +479,8 @@ define i1 @bor_land_right2(i1 %A, i1 %B) {
; A lor (A bor B)
define i1 @bor_lor_right1(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_right1(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %A, %B
@@ -472,7 +489,8 @@ define i1 @bor_lor_right1(i1 %A, i1 %B) {
}
define i1 @bor_lor_right2(i1 %A, i1 %B) {
; CHECK-LABEL: @bor_lor_right2(
-; CHECK-NEXT: [[RES:%.*]] = select i1 [[A:%.*]], i1 true, i1 [[B:%.*]]
+; CHECK-NEXT: [[C:%.*]] = or i1 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[RES:%.*]] = select i1 [[A]], i1 true, i1 [[C]]
; CHECK-NEXT: ret i1 [[RES]]
;
%c = or i1 %B, %A
diff --git a/llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll b/llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll
index 71aac1c4d48b..921d26387aa2 100644
--- a/llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll
+++ b/llvm/test/Transforms/SimplifyCFG/merge-cond-stores.ll
@@ -267,17 +267,18 @@ declare void @f()
define i32 @test_diamond_simple(i32* %p, i32* %q, i32 %a, i32 %b) {
; CHECK-LABEL: @test_diamond_simple(
; CHECK-NEXT: entry:
-; CHECK-NEXT: [[X2:%.*]] = icmp eq i32 [[B:%.*]], 0
-; CHECK-NEXT: [[TMP0:%.*]] = or i32 [[B]], [[A:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[TMP0]], 0
-; CHECK-NEXT: br i1 [[TMP1]], label [[TMP3:%.*]], label [[TMP2:%.*]]
-; CHECK: 2:
-; CHECK-NEXT: [[NOT_X2:%.*]] = xor i1 [[X2]], true
-; CHECK-NEXT: [[SIMPLIFYCFG_MERGE:%.*]] = zext i1 [[NOT_X2]] to i32
+; CHECK-NEXT: [[X1:%.*]] = icmp eq i32 [[A:%.*]], 0
+; CHECK-NEXT: [[Z2:%.*]] = select i1 [[X1]], i32 [[B:%.*]], i32 0
+; CHECK-NEXT: [[X2:%.*]] = icmp eq i32 [[B]], 0
+; CHECK-NEXT: [[TMP0:%.*]] = or i32 [[A]], [[B]]
+; CHECK-NEXT: [[DOTNOT:%.*]] = icmp eq i32 [[TMP0]], 0
+; CHECK-NEXT: br i1 [[DOTNOT]], label [[TMP2:%.*]], label [[TMP1:%.*]]
+; CHECK: 1:
+; CHECK-NEXT: [[SIMPLIFYCFG_MERGE:%.*]] = select i1 [[X2]], i32 [[Z2]], i32 1
; CHECK-NEXT: store i32 [[SIMPLIFYCFG_MERGE]], i32* [[P:%.*]], align 4
-; CHECK-NEXT: br label [[TMP3]]
-; CHECK: 3:
-; CHECK-NEXT: [[Z4:%.*]] = select i1 [[X2]], i32 0, i32 3
+; CHECK-NEXT: br label [[TMP2]]
+; CHECK: 2:
+; CHECK-NEXT: [[Z4:%.*]] = select i1 [[X2]], i32 [[Z2]], i32 3
; CHECK-NEXT: ret i32 [[Z4]]
;
entry:
More information about the llvm-commits
mailing list