[PATCH] D129753: [SCEV] Prove condition invariance via context

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 19 02:27:36 PDT 2022


mkazantsev added a comment.

@uabelho SCEV has decided that the backedge taken count of for.body.i is 1, so it will never reach -1:

  opt "-passes=print<scalar-evolution>"
  
  Printing analysis 'Scalar Evolution Analysis' for function 'foo':
  Classifying expressions for: @foo
    %storemerge13.i = phi i32 [ 0, %entry ], [ %dec.i, %for.inc32.i ]
    -->  {0,+,-1}<%for.body.i> U: [-1,1) S: [-1,1)                Exits: -1               LoopDispositions: { %for.body.i: Computable, %for.cond8.preheader.i: Invariant }
    %storemerge611.i = phi i64 [ 0, %for.body.i ], [ %add.i, %for.inc27.i ]
    -->  {0,+,1}<%for.cond8.preheader.i> U: [0,12) S: [0,12)              Exits: <<Unknown>>              LoopDispositions: { %for.cond8.preheader.i: Computable, %for.body.i: Variant }
    %add.i = add i64 %storemerge611.i, 1
    -->  {1,+,1}<%for.cond8.preheader.i> U: [1,13) S: [1,13)              Exits: <<Unknown>>              LoopDispositions: { %for.cond8.preheader.i: Computable, %for.body.i: Variant }
    %dec.i = add i32 %storemerge13.i, -1
    -->  {-1,+,-1}<%for.body.i> U: [-2,0) S: [-2,0)               Exits: -2               LoopDispositions: { %for.body.i: Computable, %for.cond8.preheader.i: Invariant }
  Determining loop execution counts for: @foo
  Loop %for.cond8.preheader.i: <multiple exits> Unpredictable backedge-taken count.
    exit count for for.cond8.preheader.i: ***COULDNOTCOMPUTE***
    exit count for for.inc27.i: 11
  Loop %for.cond8.preheader.i: max backedge-taken count is 11
  Loop %for.cond8.preheader.i: Unpredictable predicated backedge-taken count.
  Loop %for.body.i: backedge-taken count is 1
  Loop %for.body.i: max backedge-taken count is 1
  Loop %for.body.i: Predicated backedge-taken count is 1
   Predicates:
  
  Loop %for.body.i: Trip multiple is 2

If that is true, the transform is correct. Another thing is that I don't see why it thinks that backedge taken count is 1. Maybe existing bug exposed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129753/new/

https://reviews.llvm.org/D129753



More information about the llvm-commits mailing list