[PATCH] D38494: [ScalarEvolution] Handling for ICmp occuring in the evolution chain.

Jatin Bhateja via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 02:21:20 PDT 2017


jbhateja added a comment.

In https://reviews.llvm.org/D38494#887846, @hfinkel wrote:

> In https://reviews.llvm.org/D38494#887842, @junryoungju wrote:
>
> > can you explain me why? (I may I didn't understood why do we need to process without loop latch)
> >  I thought without latch cannot be evoluted from ICmp evolution.
> >
> > without latch loop have to me evoluted from previous SCEV operation. isn't it?
>
>
> I don't understand your statement.
>
> The point is that, in the last loop iteration, latch condition is not true, so replacing it with true is incorrect. If you have:
>
> int values[11];
>  int i = 0;
>  do {
>
>   values[i] = i != 10;
>
> } while (i++ != 10);
>
> After the loop, values should be { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }. In the 11th iteration, the comparison will be false. With this patch, we'd store 1 into the values array, even for the last iteration.


Hi Hal,

I don't see any changes in output of scalar-evolution analysis over above example with and without this patch. Following are the results

Printing analysis 'Scalar Evolution Analysis' for function 'main':
Classifying expressions for: @main

  %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
  -->  {0,+,1}<nuw><nsw><%do.body> U: [0,11) S: [0,11)          Exits: 10               LoopDispositions: { %do.body: Computable }
  %conv = zext i1 %cmp to i32
  -->  (zext i1 %cmp to i32) U: [0,2) S: [0,2)          Exits: 0                LoopDispositions: { %do.body: Variant }
  %idxprom = sext i32 %i.0 to i64
  -->  {0,+,1}<nuw><nsw><%do.body> U: [0,11) S: [0,11)          Exits: 10               LoopDispositions: { %do.body: Computable }
  %arrayidx = getelementptr inbounds [11 x i32], [11 x i32]* @values, i64 0, i64 %idxprom
  -->  {@values,+,4}<nsw><%do.body> U: [0,-3) S: [-9223372036854775808,9223372036854775805)             Exits: (40 + @values)     LoopDispositions: { %do.body: Computable }
  %inc = add nsw i32 %i.0, 1
  -->  {1,+,1}<nuw><nsw><%do.body> U: [1,12) S: [1,12)          Exits: 11               LoopDispositions: { %do.body: Computable }
  %0 = load i32, i32* getelementptr inbounds ([11 x i32], [11 x i32]* @values, i64 0, i64 10), align 8
  -->  %0 U: full-set S: full-set
  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i32 %0)
  -->  %call U: full-set S: full-set

Determining loop execution counts for: @main
Loop %do.body: backedge-taken count is 10
Loop %do.body: max backedge-taken count is 10
Loop %do.body: Predicated backedge-taken count is 10
Predicates:

Loop %do.body: Trip multiple is 11


https://reviews.llvm.org/D38494





More information about the llvm-commits mailing list