Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp =================================================================== --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -13133,6 +13133,16 @@ return N0.getOperand(0); } + // trunc (sign_ext_inreg (anyext iN X), iM) to iN --> sign_ext_inreg X to iM + if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG) { + SDValue N00 = N0.getOperand(0); + SDValue N01 = N0.getOperand(1); + if (N00.getOpcode() == ISD::ANY_EXTEND && + N00.getOperand(0).getValueType() == VT) + return DAG.getNode(ISD::SIGN_EXTEND_INREG, SDLoc(N), VT, + N00.getOperand(0), N01); + } + // If this is anyext(trunc), don't fold it, allow ourselves to be folded. if (N->hasOneUse() && (N->use_begin()->getOpcode() == ISD::ANY_EXTEND)) return SDValue();