summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-07-12 11:18:55 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-07-12 11:18:55 +0000
commitcf3715caddf2b3cc2dfcae7bf79cec38d63dd78f (patch)
treef33511112d1db4c749fabc563bcf11d184efcd2f /llvm/lib/Transforms
parentbcf1ca08e099a63c8df9d0a8ae568e44091ce8c8 (diff)
downloadbcm5719-llvm-cf3715caddf2b3cc2dfcae7bf79cec38d63dd78f.tar.gz
bcm5719-llvm-cf3715caddf2b3cc2dfcae7bf79cec38d63dd78f.zip
Revert "indvars: Improve LFTR by eliminating truncation when comparing
against a constant." This reverts commit r186107. It didn't handle wrapping arithmetic in the loop correctly and thus caused the following C program to count from 0 to UINT64_MAX instead of from 0 to 255 as intended: #include <stdio.h> int main() { unsigned char first = 0, last = 255; do { printf("%d\n", first); } while (first++ != last); } Full test case and instructions to reproduce with just the -indvars pass sent to the original review thread rather than to r186107's commit. llvm-svn: 186152
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Scalar/IndVarSimplify.cpp27
1 files changed, 4 insertions, 23 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
index ddb5b270d0c..df11e92c9ed 100644
--- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -1612,29 +1612,10 @@ LinearFunctionTestReplace(Loop *L,
<< " IVCount:\t" << *IVCount << "\n");
IRBuilder<> Builder(BI);
-
- unsigned CmpIndVarSize = SE->getTypeSizeInBits(CmpIndVar->getType());
- unsigned ExitCntSize = SE->getTypeSizeInBits(ExitCnt->getType());
- if (CmpIndVarSize > ExitCntSize) {
- const SCEVAddRecExpr *AR = cast<SCEVAddRecExpr>(SE->getSCEV(IndVar));
- const SCEV *ARStart = AR->getStart();
- const SCEV *ARStep = AR->getStepRecurrence(*SE);
- if (isa<SCEVConstant>(ARStart) && isa<SCEVConstant>(IVCount)) {
- const APInt &Start = cast<SCEVConstant>(ARStart)->getValue()->getValue();
- const APInt &Count = cast<SCEVConstant>(IVCount)->getValue()->getValue();
-
- APInt NewLimit;
- if (cast<SCEVConstant>(ARStep)->getValue()->isNegative())
- NewLimit = Start - Count.zext(CmpIndVarSize);
- else
- NewLimit = Start + Count.zext(CmpIndVarSize);
- ExitCnt = ConstantInt::get(CmpIndVar->getType(), NewLimit);
-
- DEBUG(dbgs() << " Widen RHS:\t" << *ExitCnt << "\n");
- } else {
- CmpIndVar = Builder.CreateTrunc(CmpIndVar, ExitCnt->getType(),
- "lftr.wideiv");
- }
+ if (SE->getTypeSizeInBits(CmpIndVar->getType())
+ > SE->getTypeSizeInBits(ExitCnt->getType())) {
+ CmpIndVar = Builder.CreateTrunc(CmpIndVar, ExitCnt->getType(),
+ "lftr.wideiv");
}
Value *Cond = Builder.CreateICmp(P, CmpIndVar, ExitCnt, "exitcond");
OpenPOWER on IntegriCloud