Skip to content

Commit d3587ec

Browse files
committed
Reapply "[SCEV] Fold (C1 * A /u C2) -> A /u (C2 /u C1), if C2 > C1." (llvm#158328)
This reverts commit fd58f23. The recommit contains an extra check to make sure that D is a multiple of C2, if C2 > C1. This fixes the issue causing the revert fd58f23. Tests have been added in 6a726e9. Original message: If C2 >u C1 and C1 >u 1, fold to A /u (C2 /u C1). Depends on llvm#157555. Alive2 Proof: https://alive2.llvm.org/ce/z/BWvQYN PR: llvm#157656 (cherry picked from commit f78150d)
1 parent 41b6b30 commit d3587ec

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

llvm/lib/Analysis/ScalarEvolution.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,14 +3230,15 @@ const SCEV *ScalarEvolution::getMulExpr(SmallVectorImpl<const SCEV *> &Ops,
32303230
match(Ops[1], m_scev_UDiv(m_SCEV(D), m_SCEVConstant(C2))) &&
32313231
C2->getAPInt().isPowerOf2() &&
32323232
C1V.logBase2() <= getMinTrailingZeros(D)) {
3233-
const SCEV *NewMul;
3233+
const SCEV *NewMul = nullptr;
32343234
if (C1V.uge(C2->getAPInt())) {
32353235
NewMul = getMulExpr(getUDivExpr(getConstant(C1V), C2), D);
3236-
} else {
3236+
} else if (C2->getAPInt().logBase2() <= getMinTrailingZeros(D)) {
32373237
assert(C1V.ugt(1) && "C1 <= 1 should have been folded earlier");
32383238
NewMul = getUDivExpr(D, getUDivExpr(C2, getConstant(C1V)));
32393239
}
3240-
return C1V == LHSC->getAPInt() ? NewMul : getNegativeSCEV(NewMul);
3240+
if (NewMul)
3241+
return C1V == LHSC->getAPInt() ? NewMul : getNegativeSCEV(NewMul);
32413242
}
32423243
}
32433244
}

0 commit comments

Comments
 (0)