@@ -3217,26 +3217,18 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
32173217 }
32183218
32193219 // Try to fold (C1 * D /u C2) -> C1/C2 * D, if C1 and C2 are powers-of-2,
3220- // D is a multiple of C2, and C1 is a multiple of C2. If C2 is a multiple
3221- // of C1, fold to (D /u (C2 /u C1)).
3220+ // D is a multiple of C2, and C1 is a multiple of C2.
32223221 const SCEV *D;
32233222 APInt C1V = LHSC->getAPInt();
3224- // (C1 * D /u C2) == -1 * -C1 * D /u C2 when C1 != INT_MIN. Don't treat -1
3225- // as -1 * 1, as it won't enable additional folds.
3226- if (C1V.isNegative() && !C1V.isMinSignedValue() && !C1V.isAllOnes())
3223+ // (C1 * D /u C2) == -1 * -C1 * D /u C2 when C1 != INT_MIN.
3224+ if (C1V.isNegative() && !C1V.isMinSignedValue())
32273225 C1V = C1V.abs();
32283226 const SCEVConstant *C2;
32293227 if (C1V.isPowerOf2() &&
32303228 match(Ops[1], m_scev_UDiv(m_SCEV(D), m_SCEVConstant(C2))) &&
3231- C2->getAPInt().isPowerOf2() &&
3229+ C2->getAPInt().isPowerOf2() && C1V.uge(C2->getAPInt()) &&
32323230 C1V.logBase2() <= getMinTrailingZeros(D)) {
3233- const SCEV *NewMul;
3234- if (C1V.uge(C2->getAPInt())) {
3235- NewMul = getMulExpr(getUDivExpr(getConstant(C1V), C2), D);
3236- } else {
3237- assert(C1V.ugt(1) && "C1 <= 1 should have been folded earlier");
3238- NewMul = getUDivExpr(D, getUDivExpr(C2, getConstant(C1V)));
3239- }
3231+ const SCEV *NewMul = getMulExpr(getUDivExpr(getConstant(C1V), C2), D);
32403232 return C1V == LHSC->getAPInt() ? NewMul : getNegativeSCEV(NewMul);
32413233 }
32423234 }
0 commit comments