[PATCH] D38494: [ScalarEvolution] Handling for ICmp occuring in the evolution chain.
Jun Ryung Ju via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 17 03:46:10 PDT 2017
junryoungju added a comment.
In https://reviews.llvm.org/D38494#899255, @jbhateja wrote:
> In https://reviews.llvm.org/D38494#888590, @sanjoy wrote:
>
> > With this IR:
> >
> > define void @f() {
> > entry:
> > br label %loop
> >
> > loop:
> > %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
> > %iv.inc = add i32 %iv, 1
> > %cmp = icmp ne i32 %iv.inc, 10
> > %cmp.zext = zext i1 %cmp to i32
> > br i1 %cmp, label %loop, label %leave
> >
> > leave:
> > ret void
> > }
> >
> >
> > and `opt -analyze -scalar-evolution` , on master:
> >
> > Printing analysis 'Scalar Evolution Analysis' for function 'f':
> > Classifying expressions for: @f
> > %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
> > --> {0,+,1}<%loop> U: [0,10) S: [0,10) Exits: 9 LoopDispositions: { %loop: Computable }
> > %iv.inc = add i32 %iv, 1
> > --> {1,+,1}<%loop> U: [1,11) S: [1,11) Exits: 10 LoopDispositions: { %loop: Computable }
> > %cmp.zext = zext i1 %cmp to i32
> > --> (zext i1 %cmp to i32) U: [0,2) S: [0,2) Exits: 0 LoopDispositions: { %loop: Variant }
> > Determining loop execution counts for: @f
> > Loop %loop: backedge-taken count is 9
> > Loop %loop: max backedge-taken count is 9
> > Loop %loop: Predicated backedge-taken count is 9
> > Predicates:
> >
> > Loop %loop: Trip multiple is 10
> >
> >
> > and with your patch:
> >
> > Printing analysis 'Scalar Evolution Analysis' for function 'f':
> > Classifying expressions for: @f
> > %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
> > --> {0,+,1}<%loop> U: [0,10) S: [0,10) Exits: 9 LoopDispositions: { %loop: Computable }
> > %iv.inc = add i32 %iv, 1
> > --> {1,+,1}<%loop> U: [1,11) S: [1,11) Exits: 10 LoopDispositions: { %loop: Computable }
> > %cmp.zext = zext i1 %cmp to i32
> > --> 1 U: [1,2) S: [1,2) Exits: 1 LoopDispositions: { %loop: Invariant }
> > Determining loop execution counts for: @f
> > Loop %loop: backedge-taken count is 9
> > Loop %loop: max backedge-taken count is 9
> > Loop %loop: Predicated backedge-taken count is 9
> > Predicates:
> >
> > Loop %loop: Trip multiple is 10
> >
> >
> > Note that the SCEV for `%cmp.zext` is different. I'm not sure how you got a
> > different answer on your end, since this should basically be the same as the IR
> > from Hal's example. Perhaps in the example you tried the icmp feeding in to the
> > latch was a different llvm::Instruction than the icmp feeding into the zext? If
> > so, that's a missing-CSE bug.
>
>
> @sanjoy , with the latest revision changes following is the result of scalar evolution analysis for above example.
>
> PROMPT>opt -analyze -scalar-evolution sdas.ll
> Printing analysis 'Scalar Evolution Analysis' for function 'f':
> Classifying expressions for: @f
>
> %iv = phi i32 [ 0, %entry ], [ %iv.inc, %loop ]
> --> {0,+,1}<%loop> U: [0,10) S: [0,10) Exits: 9 LoopDispositions: { %loop: Computable }
> %iv.inc = add i32 %iv, 1
> --> {1,+,1}<%loop> U: [1,11) S: [1,11) Exits: 10 LoopDispositions: { %loop: Computable }
> %cmp.zext = zext i1 %cmp to i32
> --> (zext i1 %cmp to i32) U: [0,2) S: [0,2) Exits: 0 LoopDispositions: { %loop: Variant }
>
> Determining loop execution counts for: @f
> Loop %loop: backedge-taken count is 9
> Loop %loop: max backedge-taken count is 9
> Loop %loop: Predicated backedge-taken count is 9
>
> Predicates:
>
>
> Loop %loop: Trip multiple is 10
I don't think this is correct way to solve problem.
because it doesn't know that how much AddExpr increasing to target.
try this code.
int foo() {
int start = 0;
int end = 10000;
int tag = 0;
do {
tag = 0;
if (start < end) start+=2, tag = 1;
} while (tag);
return 0;
}
This will not optimized ( I have tested this code )
https://reviews.llvm.org/D38494
More information about the llvm-commits
mailing list