@@ -10197,20 +10197,26 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
1019710197 }
1019810198 }
1019910199
10200- // fold (not (or A, B)) -> and(not(A), not(B))
10200+ // fold (not (or A, or(B, C))) -> and(not(A), and( not(B), not(C ))
1020110201 if (TLI.hasAndNot(SDValue(N, 0))) {
1020210202 // If we have AndNot then it is profitable to apply demorgan to make use
1020310203 // of the machine instruction.
1020410204 SDValue A;
1020510205 SDValue B;
10206+ SDValue C;
1020610207 APInt Cst;
10207- if (sd_match(N, m_Xor(m_Or(m_Value(A), m_Value(B)), m_ConstInt(Cst))) &&
10208+ if (sd_match(N, m_Xor(m_Or(m_Value(A), m_Or( m_Value(B), m_Value(C) )), m_ConstInt(Cst))) &&
1020810209 Cst.isAllOnes()) {
1020910210 auto Ty = N->getValueType(0);
10211+
10212+ auto NegA = DAG.getNode(ISD::XOR, DL, VT, A, DAG.getConstant(Cst, DL, Ty));
10213+ auto NegB = DAG.getNode(ISD::XOR, DL, VT, B, DAG.getConstant(Cst, DL, Ty));
10214+ auto NegC = DAG.getNode(ISD::XOR, DL, VT, C, DAG.getConstant(Cst, DL, Ty));
10215+
1021010216 return DAG.getNode(
1021110217 ISD::AND, DL, VT,
10212- DAG.getNode(ISD::XOR, DL, VT, A, DAG.getConstant(Cst, DL, Ty)) ,
10213- DAG.getNode(ISD::XOR , DL, VT, B, DAG.getConstant(Cst, DL, Ty) ));
10218+ NegA ,
10219+ DAG.getNode(ISD::AND , DL, VT, NegB, NegC ));
1021410220 }
1021510221 }
1021610222
0 commit comments