mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-19 17:24:57 +00:00
Teach getExactSDiv to evaluate x/1 to x up front, as it's a common
enough special case, and it theoretically allows more folding because it works even when x is unanalyzable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106763 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -414,20 +414,28 @@ static const SCEV *getExactSDiv(const SCEV *LHS, const SCEV *RHS,
|
|||||||
if (LHS == RHS)
|
if (LHS == RHS)
|
||||||
return SE.getConstant(LHS->getType(), 1);
|
return SE.getConstant(LHS->getType(), 1);
|
||||||
|
|
||||||
// Handle x /s -1 as x * -1, to give ScalarEvolution a chance to do some
|
// Handle a few RHS special cases.
|
||||||
// folding.
|
const SCEVConstant *RC = dyn_cast<SCEVConstant>(RHS);
|
||||||
if (RHS->isAllOnesValue())
|
if (RC) {
|
||||||
return SE.getMulExpr(LHS, RHS);
|
const APInt &RA = RC->getValue()->getValue();
|
||||||
|
// Handle x /s -1 as x * -1, to give ScalarEvolution a chance to do
|
||||||
|
// some folding.
|
||||||
|
if (RA.isAllOnesValue())
|
||||||
|
return SE.getMulExpr(LHS, RC);
|
||||||
|
// Handle x /s 1 as x.
|
||||||
|
if (RA == 1)
|
||||||
|
return LHS;
|
||||||
|
}
|
||||||
|
|
||||||
// Check for a division of a constant by a constant.
|
// Check for a division of a constant by a constant.
|
||||||
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(LHS)) {
|
if (const SCEVConstant *C = dyn_cast<SCEVConstant>(LHS)) {
|
||||||
const SCEVConstant *RC = dyn_cast<SCEVConstant>(RHS);
|
|
||||||
if (!RC)
|
if (!RC)
|
||||||
return 0;
|
return 0;
|
||||||
if (C->getValue()->getValue().srem(RC->getValue()->getValue()) != 0)
|
const APInt &LA = C->getValue()->getValue();
|
||||||
|
const APInt &RA = RC->getValue()->getValue();
|
||||||
|
if (LA.srem(RA) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
return SE.getConstant(C->getValue()->getValue()
|
return SE.getConstant(LA.sdiv(RA));
|
||||||
.sdiv(RC->getValue()->getValue()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Distribute the sdiv over addrec operands, if the addrec doesn't overflow.
|
// Distribute the sdiv over addrec operands, if the addrec doesn't overflow.
|
||||||
|
Reference in New Issue
Block a user