[InstSimplify] X && !(X || Y) --> false

https://alive2.llvm.org/ce/z/7J8Exr

This is a commuted variant that was not included in:
D138853 / f297332749
This commit is contained in:
Sanjay Patel committed 2023-01-26 13:38:43 -05:00
1 parent a56a02bc7e
commit 7dbeb127ea
2 files changed
+5 -8

No files matched your search

@@ -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())))
@@ -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
@@ -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