diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2014-11-16 07:30:35 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2014-11-16 07:30:35 +0000 |
| commit | 0df1d1247614a0f3b94e00ac7e54665af4395620 (patch) | |
| tree | 969eeb4dcd85560e3b022bd473693ad0db5f90af /llvm/lib/Analysis/ScalarEvolution.cpp | |
| parent | 5854e9fae8cd340ee6b6f1150809a0fb5908838e (diff) | |
| download | bcm5719-llvm-0df1d1247614a0f3b94e00ac7e54665af4395620.tar.gz bcm5719-llvm-0df1d1247614a0f3b94e00ac7e54665af4395620.zip | |
ScalarEvolution: HowFarToZero was wrongly using signed division
HowFarToZero was supposed to use unsigned division in order to calculate
the backedge taken count. However, SCEVDivision::divide performs signed
division. Unless I am mistaken, no users of SCEVDivision actually want
signed arithmetic: switch to udiv and urem.
This fixes PR21578.
llvm-svn: 222093
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolution.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 55472ecb667..2026f8aa79c 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -675,32 +675,32 @@ static void GroupByComplexity(SmallVectorImpl<const SCEV *> &Ops, } } -static const APInt srem(const SCEVConstant *C1, const SCEVConstant *C2) { +static const APInt urem(const SCEVConstant *C1, const SCEVConstant *C2) { APInt A = C1->getValue()->getValue(); APInt B = C2->getValue()->getValue(); uint32_t ABW = A.getBitWidth(); uint32_t BBW = B.getBitWidth(); if (ABW > BBW) - B = B.sext(ABW); + B = B.zext(ABW); else if (ABW < BBW) - A = A.sext(BBW); + A = A.zext(BBW); - return APIntOps::srem(A, B); + return APIntOps::urem(A, B); } -static const APInt sdiv(const SCEVConstant *C1, const SCEVConstant *C2) { +static const APInt udiv(const SCEVConstant *C1, const SCEVConstant *C2) { APInt A = C1->getValue()->getValue(); APInt B = C2->getValue()->getValue(); uint32_t ABW = A.getBitWidth(); uint32_t BBW = B.getBitWidth(); if (ABW > BBW) - B = B.sext(ABW); + B = B.zext(ABW); else if (ABW < BBW) - A = A.sext(BBW); + A = A.zext(BBW); - return APIntOps::sdiv(A, B); + return APIntOps::udiv(A, B); } namespace { @@ -803,8 +803,8 @@ public: void visitConstant(const SCEVConstant *Numerator) { if (const SCEVConstant *D = dyn_cast<SCEVConstant>(Denominator)) { - Quotient = SE.getConstant(sdiv(Numerator, D)); - Remainder = SE.getConstant(srem(Numerator, D)); + Quotient = SE.getConstant(udiv(Numerator, D)); + Remainder = SE.getConstant(urem(Numerator, D)); return; } } |

