Skip to content

Commit

Permalink
[InstSimplify] X && !(X || Y) --> false
Browse files Browse the repository at this point in the history
https://alive2.llvm.org/ce/z/7J8Exr

This is a commuted variant that was not included in:
D138853 / f297332
  • Loading branch information
rotateright committed Jan 26, 2023
1 parent a56a02b commit 7dbeb12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
3 changes: 3 additions & 0 deletions llvm/lib/Analysis/InstructionSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4598,6 +4598,9 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
// !(X || Y) && X --> false (commuted 2 ways)
if (match(Cond, m_Not(m_c_LogicalOr(m_Specific(TrueVal), m_Value()))))
return ConstantInt::getFalse(Cond->getType());
// X && !(X || Y) --> false (commuted 2 ways)
if (match(TrueVal, m_Not(m_c_LogicalOr(m_Specific(Cond), m_Value()))))
return ConstantInt::getFalse(Cond->getType());

// (X || Y) && Y --> Y (commuted 2 ways)
if (match(Cond, m_c_LogicalOr(m_Specific(TrueVal), m_Value())))
Expand Down
10 changes: 2 additions & 8 deletions llvm/test/Transforms/InstSimplify/select-logical.ll
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,7 @@ define i1 @logical_or_not_and_commute_or(i1 %x, i1 %y) {

define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {
; CHECK-LABEL: @logical_or_not_commute_and(
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
; CHECK-NEXT: [[R:%.*]] = select i1 [[X]], i1 [[NOT]], i1 false
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 false
;
%l.and = select i1 %x, i1 true, i1 %y
%not = xor i1 %l.and, true
Expand All @@ -215,10 +212,7 @@ define i1 @logical_or_not_commute_and(i1 %x, i1 %y) {

define i1 @logical_or_not_commute_and_commute_or(i1 %x, i1 %y) {
; CHECK-LABEL: @logical_or_not_commute_and_commute_or(
; CHECK-NEXT: [[L_AND:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[L_AND]], true
; CHECK-NEXT: [[R:%.*]] = select i1 [[Y]], i1 [[NOT]], i1 false
; CHECK-NEXT: ret i1 [[R]]
; CHECK-NEXT: ret i1 false
;
%l.and = select i1 %x, i1 true, i1 %y
%not = xor i1 %l.and, true
Expand Down

0 comments on commit 7dbeb12

Please sign in to comment.