return replaceOperand(SI, 0, A);
}
- // sel (sel c, a, false), true, (sel !c, b, false) -> sel c, a, b
- // sel (sel !c, a, false), true, (sel c, b, false) -> sel c, b, a
+ // (c && a) || (!c && b) --> sel c, a, b
+ // (!c && a) || (c && b) --> sel c, b, a
Value *C1, *C2;
- if (match(CondVal, m_Select(m_Value(C1), m_Value(A), m_Zero())) &&
+ if (match(CondVal, m_LogicalAnd(m_Value(C1), m_Value(A))) &&
match(TrueVal, m_One()) &&
- match(FalseVal, m_Select(m_Value(C2), m_Value(B), m_Zero()))) {
+ match(FalseVal, m_LogicalAnd(m_Value(C2), m_Value(B)))) {
if (match(C2, m_Not(m_Specific(C1)))) // first case
return SelectInst::Create(C1, A, B);
else if (match(C1, m_Not(m_Specific(C2)))) // second case
define i1 @bools_logical_commute0_and1(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools_logical_commute0_and1(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = and i1 [[NOT]], [[A:%.*]]
-; CHECK-NEXT: [[AND2:%.*]] = select i1 [[C]], i1 [[B:%.*]], i1 false
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1
define i1 @bools_logical_commute0_and2(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools_logical_commute0_and2(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = select i1 [[NOT]], i1 [[A:%.*]], i1 false
-; CHECK-NEXT: [[AND2:%.*]] = and i1 [[C]], [[B:%.*]]
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1
define i1 @bools_logical_commute0_and1_and2(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools_logical_commute0_and1_and2(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = and i1 [[NOT]], [[A:%.*]]
-; CHECK-NEXT: [[AND2:%.*]] = and i1 [[C]], [[B:%.*]]
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1
define i1 @bools2_logical_commute0_and1(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools2_logical_commute0_and1(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = and i1 [[C]], [[A:%.*]]
-; CHECK-NEXT: [[AND2:%.*]] = select i1 [[NOT]], i1 [[B:%.*]], i1 false
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[A:%.*]], i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1
define i1 @bools2_logical_commute0_and2(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools2_logical_commute0_and2(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = select i1 [[C]], i1 [[A:%.*]], i1 false
-; CHECK-NEXT: [[AND2:%.*]] = and i1 [[NOT]], [[B:%.*]]
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[A:%.*]], i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1
define i1 @bools2_logical_commute0_and1_and2(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools2_logical_commute0_and1_and2(
-; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[C:%.*]], true
-; CHECK-NEXT: [[AND1:%.*]] = and i1 [[C]], [[A:%.*]]
-; CHECK-NEXT: [[AND2:%.*]] = and i1 [[NOT]], [[B:%.*]]
-; CHECK-NEXT: [[OR:%.*]] = select i1 [[AND1]], i1 true, i1 [[AND2]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[A:%.*]], i1 [[B:%.*]]
; CHECK-NEXT: ret i1 [[OR]]
;
%not = xor i1 %c, -1