Index: lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp =================================================================== --- lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -604,7 +604,10 @@ SDValue DAGTypeLegalizer::PromoteIntRes_SHL(SDNode *N) { SDValue Res = GetPromotedInteger(N->getOperand(0)); SDValue Amt = N->getOperand(1); - if (!TLI.isTypeLegal(Amt.getValueType())) + // Careful: we only want to extend Amt if it's illegal due to being too + // small, not too large. + if (!TLI.isTypeLegal(Amt.getValueType()) && + Amt.getValueType().bitsLT(Res.getValueType())) Amt = ZExtPromotedInteger(N->getOperand(1)); return DAG.getNode(ISD::SHL, SDLoc(N), Res.getValueType(), Res, Amt); } @@ -629,7 +632,8 @@ // The input value must be properly sign extended. SDValue Res = SExtPromotedInteger(N->getOperand(0)); SDValue Amt = N->getOperand(1); - if (!TLI.isTypeLegal(Amt.getValueType())) + if (!TLI.isTypeLegal(Amt.getValueType()) && + Amt.getValueType().bitsLT(Res.getValueType())) Amt = ZExtPromotedInteger(N->getOperand(1)); return DAG.getNode(ISD::SRA, SDLoc(N), Res.getValueType(), Res, Amt); } @@ -638,7 +642,8 @@ // The input value must be properly zero extended. SDValue Res = ZExtPromotedInteger(N->getOperand(0)); SDValue Amt = N->getOperand(1); - if (!TLI.isTypeLegal(Amt.getValueType())) + if (!TLI.isTypeLegal(Amt.getValueType()) && + Amt.getValueType().bitsLT(Res.getValueType())) Amt = ZExtPromotedInteger(N->getOperand(1)); return DAG.getNode(ISD::SRL, SDLoc(N), Res.getValueType(), Res, Amt); }