diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2013-07-12 11:18:55 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2013-07-12 11:18:55 +0000 |
commit | 6f0ec20e8fa23e9588205ea0eaba8f3021abe1ac (patch) | |
tree | 4922e9ce6f2aed915948586459a599215edbc4b9 | |
parent | dd51a0c1e0b3cce8093244533b3505668d16f218 (diff) | |
download | llvm-6f0ec20e8fa23e9588205ea0eaba8f3021abe1ac.tar.gz llvm-6f0ec20e8fa23e9588205ea0eaba8f3021abe1ac.tar.bz2 llvm-6f0ec20e8fa23e9588205ea0eaba8f3021abe1ac.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186152 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 27 | ||||
-rw-r--r-- | test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll | 25 |
2 files changed, 4 insertions, 48 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index ddb5b270d0..df11e92c9e 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/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"); diff --git a/test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll b/test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll deleted file mode 100644 index 185a67f282..0000000000 --- a/test/Transforms/IndVarSimplify/exitcnt-const-arstart-const-opt.ll +++ /dev/null @@ -1,25 +0,0 @@ -;RUN: opt -S %s -indvars | FileCheck %s - -; Function Attrs: nounwind uwtable -define void @foo() #0 { -entry: - br label %for.body - -for.body: ; preds = %entry, %for.body - %i.01 = phi i16 [ 0, %entry ], [ %inc, %for.body ] - %conv2 = sext i16 %i.01 to i32 - call void @bar(i32 %conv2) #1 - %inc = add i16 %i.01, 1 -;CHECK-NOT: %lftr.wideiv = trunc i32 %indvars.iv.next to i16 -;CHECK: %exitcond = icmp ne i32 %indvars.iv.next, 512 - %cmp = icmp slt i16 %inc, 512 - br i1 %cmp, label %for.body, label %for.end - -for.end: ; preds = %for.body - ret void -} - -declare void @bar(i32) - -attributes #0 = { nounwind uwtable } -attributes #1 = { nounwind } |