[llvm] [DA] Check monotonicity for subscripts (PR #154527)

Ryotaro Kasuga via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 29 05:10:53 PDT 2025


kasuga-fj wrote:

I found a case where `getRange` is insufficient even if the backedge-taken count is constant. Consider the following:

```llvm
; for (int i = 0; i < 100; i++)
;   a[i & 1] = 0;
define void @f(ptr %a) {
entry:
  br label %loop

loop:
  %i = phi i64 [ 0, %entry ], [ %i.inc, %loop ]
  %i.1 = phi i1 [ false, %entry ], [ %i.1.inc, %loop ]
  %offset = sext i1 %i.1 to i64
  %idx = getelementptr i8, ptr %a, i64 %offset
  store i8 0, ptr %idx
  %i.inc = add i64 %i, 1
  %i.1.inc = add i1 %i.1, true
  %exitcond = icmp eq i64 %i.inc, 100
  br i1 %exitcond, label %exit, label %loop

exit:
  ret void
}

```

As I tested locally, `ScalarEvolution::getSignedRange` returned `[-1, 1)` for `(sext i1 {false,+,true}<%loop> to i64)` (which is the SCEV expression for `%offset`), and `ConstantRange::isWrappedSignedSet` returned `false`.

https://github.com/llvm/llvm-project/pull/154527


More information about the llvm-commits mailing list