Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -3766,7 +3766,7 @@ EVT VT = N->getValueType(0); if (VT != MVT::i64 && VT != MVT::i32 && VT != MVT::i16) return SDValue(); - if (!TLI.isOperationLegalOrCustom(ISD::BSWAP, VT)) + if (!TLI.isOperationLegal(ISD::BSWAP, VT)) return SDValue(); // Recognize (and (shl a, 8), 0xff), (and (srl a, 8), 0xff00) @@ -3878,36 +3878,27 @@ if (Opc != ISD::AND && Opc != ISD::SHL && Opc != ISD::SRL) return false; - SDValue N0 = N.getOperand(0); - unsigned Opc0 = N0.getOpcode(); - if (Opc0 != ISD::AND && Opc0 != ISD::SHL && Opc0 != ISD::SRL) - return false; - - ConstantSDNode *N1C = nullptr; - // SHL or SRL: look upstream for AND mask operand - if (Opc == ISD::AND) - N1C = dyn_cast(N.getOperand(1)); - else if (Opc0 == ISD::AND) - N1C = dyn_cast(N0.getOperand(1)); + ConstantSDNode *N1C = dyn_cast(N.getOperand(1)); if (!N1C) return false; - unsigned mask; + unsigned Num; switch (N1C->getZExtValue()) { default: return false; - case 0xFF: mask = 0; break; - case 0xFF00: mask = 1; break; - case 0xFF0000: mask = 2; break; - case 0xFF000000: mask = 3; break; + case 0xFF: Num = 0; break; + case 0xFF00: Num = 1; break; + case 0xFF0000: Num = 2; break; + case 0xFF000000: Num = 3; break; } // Look for (x & 0xff) << 8 as well as ((x << 8) & 0xff00). + SDValue N0 = N.getOperand(0); if (Opc == ISD::AND) { - if (mask == 0 || mask == 2) { + if (Num == 0 || Num == 2) { // (x >> 8) & 0xff // (x >> 8) & 0xff0000 - if (Opc0 != ISD::SRL) + if (N0.getOpcode() != ISD::SRL) return false; ConstantSDNode *C = dyn_cast(N0.getOperand(1)); if (!C || C->getZExtValue() != 8) @@ -3915,7 +3906,7 @@ } else { // (x << 8) & 0xff00 // (x << 8) & 0xff000000 - if (Opc0 != ISD::SHL) + if (N0.getOpcode() != ISD::SHL) return false; ConstantSDNode *C = dyn_cast(N0.getOperand(1)); if (!C || C->getZExtValue() != 8) @@ -3924,7 +3915,7 @@ } else if (Opc == ISD::SHL) { // (x & 0xff) << 8 // (x & 0xff0000) << 8 - if (mask != 0 && mask != 2) + if (Num != 0 && Num != 2) return false; ConstantSDNode *C = dyn_cast(N.getOperand(1)); if (!C || C->getZExtValue() != 8) @@ -3932,17 +3923,17 @@ } else { // Opc == ISD::SRL // (x & 0xff00) >> 8 // (x & 0xff000000) >> 8 - if (mask != 1 && mask != 3) + if (Num != 1 && Num != 3) return false; ConstantSDNode *C = dyn_cast(N.getOperand(1)); if (!C || C->getZExtValue() != 8) return false; } - if (Parts[mask]) + if (Parts[Num]) return false; - Parts[mask] = N0.getOperand(0).getNode(); + Parts[Num] = N0.getOperand(0).getNode(); return true; } @@ -3959,7 +3950,7 @@ EVT VT = N->getValueType(0); if (VT != MVT::i32) return SDValue(); - if (!TLI.isOperationLegalOrCustom(ISD::BSWAP, VT)) + if (!TLI.isOperationLegal(ISD::BSWAP, VT)) return SDValue(); // Look for either @@ -3974,15 +3965,18 @@ if (N1.getOpcode() == ISD::OR && N00.getNumOperands() == 2 && N01.getNumOperands() == 2) { // (or (or (and), (and)), (or (and), (and))) - if (!isBSwapHWordElement(N00, Parts)) + SDValue N000 = N00.getOperand(0); + if (!isBSwapHWordElement(N000, Parts)) return SDValue(); - if (!isBSwapHWordElement(N01, Parts)) + + SDValue N001 = N00.getOperand(1); + if (!isBSwapHWordElement(N001, Parts)) return SDValue(); - SDValue N10 = N1.getOperand(0); - if (!isBSwapHWordElement(N10, Parts)) + SDValue N010 = N01.getOperand(0); + if (!isBSwapHWordElement(N010, Parts)) return SDValue(); - SDValue N11 = N1.getOperand(1); - if (!isBSwapHWordElement(N11, Parts)) + SDValue N011 = N01.getOperand(1); + if (!isBSwapHWordElement(N011, Parts)) return SDValue(); } else { // (or (or (or (and), (and)), (and)), (and))