@@ -3048,12 +3048,6 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3048
3048
auto IsPowerOfTwo = [](ConstantSDNode *C) {
3049
3049
if (C->isNullValue() || C->isOpaque())
3050
3050
return false;
3051
- // The instruction sequence to be generated contains shifting C by (op size
3052
- // in bits - # of trailing zeros in C), which results in an undef value when
3053
- // C == 1. (e.g. if the op size in bits is 32, it will be (sra x , 32) if C
3054
- // == 1)
3055
- if (C->getAPIntValue().isOneValue())
3056
- return false;
3057
3051
if (C->getAPIntValue().isAllOnesValue())
3058
3052
return false;
3059
3053
if (C->getAPIntValue().isMinSignedValue())
@@ -3100,14 +3094,16 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3100
3094
3101
3095
// If dividing by a positive value, we're done. Otherwise, the result must
3102
3096
// be negated.
3103
- SDValue Sub =
3104
- DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT) , Sra);
3097
+ SDValue Zero = DAG.getConstant(0, DL, VT);
3098
+ SDValue Sub = DAG.getNode(ISD::SUB, DL, VT, Zero , Sra);
3105
3099
3106
3100
// FIXME: Use SELECT_CC once we improve SELECT_CC constant-folding.
3107
3101
SDValue Res = DAG.getSelect(
3108
- DL, VT,
3109
- DAG.getSetCC(DL, VT, N1, DAG.getConstant(0, DL, VT), ISD::SETLT), Sub,
3110
- Sra);
3102
+ DL, VT, DAG.getSetCC(DL, VT, N1, Zero, ISD::SETLT), Sub, Sra);
3103
+ // Special case: (sdiv X, 1) -> X
3104
+ SDValue One = DAG.getConstant(1, DL, VT);
3105
+ Res = DAG.getSelect(DL, VT, DAG.getSetCC(DL, VT, N1, One, ISD::SETEQ), N0,
3106
+ Res);
3111
3107
return Res;
3112
3108
}
3113
3109
0 commit comments