diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-06-21 11:47:18 +0000 |
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-06-21 11:47:18 +0000 |
| commit | 8dd637aa04067837056633aedd3d15e0af4f2685 (patch) | |
| tree | 747762ed7a920e53c04acc873504b1a821a6e963 /llvm | |
| parent | d253e66ec7eaabd5171dc9ba79da78f62156df42 (diff) | |
| download | bcm5719-llvm-8dd637aa04067837056633aedd3d15e0af4f2685.tar.gz bcm5719-llvm-8dd637aa04067837056633aedd3d15e0af4f2685.zip | |
SCEVExpander: Fold constant PHIs harder. The logic below only understands proper IVs.
PR20093.
llvm-svn: 211433
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 3 | ||||
| -rw-r--r-- | llvm/test/Transforms/IndVarSimplify/2014-06-21-congruent-constant.ll | 51 |
2 files changed, 53 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index b5070434d14..8c75b0db70f 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -16,6 +16,7 @@ #include "llvm/Analysis/ScalarEvolutionExpander.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallSet.h" +#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" #include "llvm/IR/DataLayout.h" @@ -1706,7 +1707,7 @@ unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT, // Fold constant phis. They may be congruent to other constant phis and // would confuse the logic below that expects proper IVs. - if (Value *V = Phi->hasConstantValue()) { + if (Value *V = SimplifyInstruction(Phi, SE.DL, SE.TLI, SE.DT)) { Phi->replaceAllUsesWith(V); DeadInsts.push_back(Phi); ++NumElim; diff --git a/llvm/test/Transforms/IndVarSimplify/2014-06-21-congruent-constant.ll b/llvm/test/Transforms/IndVarSimplify/2014-06-21-congruent-constant.ll new file mode 100644 index 00000000000..3df4c210b4a --- /dev/null +++ b/llvm/test/Transforms/IndVarSimplify/2014-06-21-congruent-constant.ll @@ -0,0 +1,51 @@ +; RUN: opt -S -loop-unswitch -instcombine -indvars < %s | FileCheck %s + +@c = external global i32**, align 8 + +define void @test1() { +entry: + br i1 undef, label %for.end12, label %for.cond.preheader + +for.cond.preheader: ; preds = %entry + %0 = load i32*** @c, align 8 + %1 = load i32** %0, align 8 + %2 = load i32* %1, align 4 + br label %for.body + +for.body: ; preds = %for.cond.backedge, %for.body9.us, %for.cond.preheader + %3 = phi i32* [ %1, %for.cond.preheader ], [ %3, %for.cond.backedge ], [ %6, %for.body9.us ] + %4 = phi i32 [ %2, %for.cond.preheader ], [ undef, %for.cond.backedge ], [ %7, %for.body9.us ] + %i.024 = phi i32 [ 0, %for.cond.preheader ], [ %inc, %for.cond.backedge ], [ 0, %for.body9.us ] + %tobool1 = icmp eq i32 %4, 0 + br i1 %tobool1, label %if.end, label %for.cond.backedge + +if.end: ; preds = %for.body + %5 = load i32* %3, align 4 + %tobool4 = icmp eq i32 %5, 0 + br i1 %tobool4, label %for.cond3, label %for.body9.preheader + +for.body9.preheader: ; preds = %if.end + %tobool8 = icmp eq i32 %i.024, 1 + br i1 %tobool8, label %for.body9.us, label %for.body9 + +for.body9.us: ; preds = %for.body9.preheader + %6 = load i32** undef, align 8 + %7 = load i32* %6, align 4 + br label %for.body + +for.cond3: ; preds = %for.cond3, %if.end + br label %for.cond3 + +for.body9: ; preds = %for.body9, %for.body9.preheader + br label %for.body9 + +for.cond.backedge: ; preds = %for.body + %inc = add nsw i32 %i.024, 1 + br i1 false, label %for.body, label %for.end12 + +for.end12: ; preds = %for.cond.backedge, %entry + ret void + +; CHECK-LABEL: @test1 +; CHECK-NOT: phi +} |

