[PATCH] D87344: [IndVars] Remove range checks for which we can predicate ends of the range

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 02:29:02 PDT 2020


mkazantsev added a comment.

Thanks for a clue Philip, you are kind of right, but I don't think we can fix exit count computation. Here's the motivating example:

  define i32 @test_01(i32* %p) {
  entry:
    %len = load i32, i32* %p, align 4, !range !0
    br label %loop
  
  loop:                                             ; preds = %backedge, %entry
    %iv = phi i32 [ %len, %entry ], [ %iv.next, %backedge ]
    %iv.next = add nsw i32 %iv, -1
    %rc = icmp slt i32 %iv.next, %len
    br i1 %rc, label %backedge, label %fail
  
  backedge:                                         ; preds = %loop
    %loop.cond = icmp ne i32 %iv, 0
    br i1 %loop.cond, label %loop, label %exit
  
  fail:                                             ; preds = %loop
    ret i32 -1
  
  exit:                                             ; preds = %backedge
    ret i32 0
  }

The block `loop` just never exits (if we leave this check alone then the loop is infinite). So formally, we do not know the exit count for this block. The only thing we can do is we can try to prove that, no matter what this exit count is, it is greater than max backedge taken count. This may work.


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

https://reviews.llvm.org/D87344



More information about the llvm-commits mailing list