Skip to content

Commit 7dbeb12

Browse files
committed
[InstSimplify] X && !(X || Y) --> false
https://alive2.llvm.org/ce/z/7J8Exr This is a commuted variant that was not included in: D138853 / f297332
1 parent a56a02b commit 7dbeb12

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4598,6 +4598,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
45984598
// !(X || Y) && X --> false (commuted 2 ways)
45994599
if (match(Cond, m_Not(m_c_LogicalOr(m_Specific(TrueVal), m_Value()))))
46004600
return ConstantInt::getFalse(Cond->getType());
4601+
// X && !(X || Y) --> false (commuted 2 ways)
4602+
if (match(TrueVal, m_Not(m_c_LogicalOr(m_Specific(Cond), m_Value()))))
4603+
return ConstantInt::getFalse(Cond->getType());
46014604

46024605
// (X || Y) && Y --> Y (commuted 2 ways)
46034606
if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Value())))

llvm/test/Transforms/InstSimplify/select-logical.ll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ define i1 @logical_or_not_and_commute_or(i1 %x, i1 %y) {
200200

201201
define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
202202
; CHECK-LABEL: @logical_or_not_commute_and(
203-
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
204-
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
205-
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOT]], i1 false
206-
; CHECK-NEXT: ret i1 [[R]]
203+
; CHECK-NEXT: ret i1 false
207204
;
208205
%l.and = select i1 %x, i1 true, i1 %y
209206
%not = xor i1 %l.and, true
@@ -215,10 +212,7 @@ define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
215212

216213
define i1 @logical_or_not_commute_and_commute_or(i1 %x, i1 %y) {
217214
; CHECK-LABEL: @logical_or_not_commute_and_commute_or(
218-
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
219-
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
220-
; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i1 [[NOT]], i1 false
221-
; CHECK-NEXT: ret i1 [[R]]
215+
; CHECK-NEXT: ret i1 false
222216
;
223217
%l.and = select i1 %x, i1 true, i1 %y
224218
%not = xor i1 %l.and, true

0 commit comments

Comments
 (0)