@@ -3045,9 +3045,7 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3045
3045
// vector of such elements.
3046
3046
SmallBitVector KnownNegatives(
3047
3047
(N1C || !VT.isVector()) ? 1 : VT.getVectorNumElements(), false);
3048
- unsigned EltIndex = 0;
3049
- auto IsPowerOfTwo = [&KnownNegatives, &EltIndex](ConstantSDNode *C) {
3050
- unsigned Idx = EltIndex++;
3048
+ auto IsPowerOfTwo = [](ConstantSDNode *C) {
3051
3049
if (C->isNullValue() || C->isOpaque())
3052
3050
return false;
3053
3051
// The instruction sequence to be generated contains shifting C by (op size
@@ -3063,10 +3061,8 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3063
3061
3064
3062
if (C->getAPIntValue().isPowerOf2())
3065
3063
return true;
3066
- if ((-C->getAPIntValue()).isPowerOf2()) {
3067
- KnownNegatives.set(Idx);
3064
+ if ((-C->getAPIntValue()).isPowerOf2())
3068
3065
return true;
3069
- }
3070
3066
return false;
3071
3067
};
3072
3068
@@ -3088,44 +3084,31 @@ SDValue DAGCombiner::visitSDIV(SDNode *N) {
3088
3084
SDValue Inexact = DAG.getNode(ISD::SUB, DL, ShiftAmtTy, Bits, C1);
3089
3085
if (!isConstantOrConstantVector(Inexact))
3090
3086
return SDValue();
3087
+
3091
3088
// Splat the sign bit into the register
3092
3089
SDValue Sign = DAG.getNode(ISD::SRA, DL, VT, N0,
3093
3090
DAG.getConstant(BitWidth - 1, DL, ShiftAmtTy));
3094
3091
AddToWorklist(Sign.getNode());
3095
3092
3096
3093
// Add (N0 < 0) ? abs2 - 1 : 0;
3097
3094
SDValue Srl = DAG.getNode(ISD::SRL, DL, VT, Sign, Inexact);
3098
- SDValue Add = DAG.getNode(ISD::ADD, DL, VT, N0, Srl);
3099
3095
AddToWorklist(Srl.getNode());
3100
- AddToWorklist(Add.getNode()); // Divide by pow2
3096
+ SDValue Add = DAG.getNode(ISD::ADD, DL, VT, N0, Srl);
3097
+ AddToWorklist(Add.getNode());
3101
3098
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Add, C1);
3099
+ AddToWorklist(Sra.getNode());
3102
3100
3103
3101
// If dividing by a positive value, we're done. Otherwise, the result must
3104
3102
// be negated.
3105
- if (KnownNegatives.none())
3106
- return Sra;
3107
-
3108
- AddToWorklist(Sra.getNode());
3109
3103
SDValue Sub =
3110
3104
DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT), Sra);
3111
- // If all shift amount elements are negative, we're done.
3112
- if (KnownNegatives.all())
3113
- return Sub;
3114
-
3115
- // Shift amount has both positive and negative elements.
3116
- assert(VT.isVector() && !N0C &&
3117
- "Expecting a non-splat vector shift amount");
3118
3105
3119
- SmallVector<SDValue, 64> VSelectMask;
3120
- for (int i = 0, e = VT.getVectorNumElements(); i < e; ++i)
3121
- VSelectMask.push_back(
3122
- DAG.getConstant(KnownNegatives[i] ? -1 : 0, DL, MVT::i1));
3123
-
3124
- SDValue Mask =
3125
- DAG.getBuildVector(EVT::getVectorVT(*DAG.getContext(), MVT::i1,
3126
- VT.getVectorElementCount()),
3127
- DL, VSelectMask);
3128
- return DAG.getNode(ISD::VSELECT, DL, VT, Mask, Sub, Sra);
3106
+ // FIXME: Use SELECT_CC once we improve SELECT_CC constant-folding.
3107
+ SDValue Res = DAG.getSelect(
3108
+ DL, VT,
3109
+ DAG.getSetCC(DL, VT, N1, DAG.getConstant(0, DL, VT), ISD::SETLT), Sub,
3110
+ Sra);
3111
+ return Res;
3129
3112
}
3130
3113
3131
3114
// If integer divide is expensive and we satisfy the requirements, emit an
0 commit comments