[llvm] r222093 - ScalarEvolution: HowFarToZero was wrongly using signed division
David Majnemer
david.majnemer at gmail.com
Sat Nov 15 23:30:35 PST 2014
Author: majnemer
Date: Sun Nov 16 01:30:35 2014
New Revision: 222093
URL: http://llvm.org/viewvc/llvm-project?rev=222093&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Analysis/ScalarEvolution.cpp
llvm/trunk/test/Analysis/ScalarEvolution/trip-count-pow2.ll
Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=222093&r1=222092&r2=222093&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Sun Nov 16 01:30:35 2014
@@ -675,32 +675,32 @@ static void GroupByComplexity(SmallVecto
}
}
-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;
}
}
Modified: llvm/trunk/test/Analysis/ScalarEvolution/trip-count-pow2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/trip-count-pow2.ll?rev=222093&r1=222092&r2=222093&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/trip-count-pow2.ll (original)
+++ llvm/trunk/test/Analysis/ScalarEvolution/trip-count-pow2.ll Sun Nov 16 01:30:35 2014
@@ -48,6 +48,6 @@ exit:
ret void
; CHECK-LABEL: @test3
-; CHECK: Loop %loop: backedge-taken count is ((-96 + (96 * %n)) /u 96)
-; CHECK: Loop %loop: max backedge-taken count is ((-96 + (96 * %n)) /u 96)
+; CHECK: Loop %loop: Unpredictable backedge-taken count.
+; CHECK: Loop %loop: Unpredictable max backedge-taken count.
}
More information about the llvm-commits
mailing list