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

Jatin Bhateja via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 3 20:32:38 PDT 2017


jbhateja added a comment.

For following C and IR references.

int foo() {

  int start = 0;
  int end = 10000;
  int tag = 0;
  do {
      tag = 0;
      if (start < end) start++, tag = 1;
  } while (tag);
  return 0;

}

do.body:                                          ; preds = %do.body, %entry

  %start.0 = phi i32 [ 0, %entry ], [ %inc.start.0, %do.body ]
  %cmp = icmp slt i32 %start.0, 10000
  %inc = zext i1 %cmp to i32
  %inc.start.0 = add nsw i32 %start.0, %inc
  br i1 %cmp, label %do.body, label %do.end

Following is the result of SCEV Analysis with the patch

PROMPT>opt -analyze -scalar-evolution test1_preana_sgt.ll
Printing analysis 'Scalar Evolution Analysis' for function 'foo':
Classifying expressions for: @foo

  %start.0 = phi i32 [ 0, %entry ], [ %inc.start.0, %do.body ]
  -->  {0,+,1}<nuw><nsw><%do.body> U: [0,10001) S: [0,10001)            Exits: 10000            LoopDispositions: { %do.body: Computable }
  %inc = zext i1 %cmp to i32
  -->  1 U: [1,2) S: [1,2)              Exits: 1                LoopDispositions: { %do.body: Invariant }
  %inc.start.0 = add nsw i32 %start.0, %inc
  -->  {1,+,1}<nuw><nsw><%do.body> U: [1,10002) S: [1,10002)            Exits: 10001            LoopDispositions: { %do.body: Computable }

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

Loop %do.body: Trip multiple is 10001.


https://reviews.llvm.org/D38494





More information about the llvm-commits mailing list