[llvm] [ConstraintElimination] Use SCEV ranges information for Loop counter (PR #91457)

via llvm-commits llvm-commits at lists.llvm.org
Thu May 9 13:55:19 PDT 2024


v01dXYZ wrote:

More precisely, here is the IR dump before constraint elimination:

``` llvm
define void @caller(i32 %n, ptr noalias nocapture nonnull writeonly %A) local_unnamed_addr {
entry:
  br label %for

for:                                              ; preds = %callee.exit, %entry
  %i = phi i32 [ 0, %entry ], [ %j.inc, %callee.exit ]
  %i.cmp = icmp slt i32 %i, %n
  br i1 %i.cmp, label %body, label %return

body:                                             ; preds = %for
  %j.cmp1.i = icmp sgt i32 %n, 0
  br i1 %j.cmp1.i, label %body.i, label %callee.exit

body.i:                                           ; preds = %body.i, %body
  %j2.i = phi i32 [ %j.inc.i, %body.i ], [ 0, %body ]
  %idx.i = add nuw i32 %j2.i, %i
  %0 = sext i32 %idx.i to i64
  %arrayidx.i = getelementptr inbounds double, ptr %A, i64 %0
  store double 4.200000e+01, ptr %arrayidx.i, align 8, !alias.scope !0
  %j.inc.i = add nuw nsw i32 %j2.i, 1
  %j.cmp.i = icmp slt i32 %j.inc.i, %n
  br i1 %j.cmp.i, label %body.i, label %callee.exit

callee.exit:                                      ; preds = %body, %body.i
  %j.inc = add nuw nsw i32 %i, 1
  br label %for

return:                                           ; preds = %for
  ret void
}
```

When adding the SCEV ranges as facts to the header, it adds `%i >= 0` which would allow elimination of `%n >= 0` in `body`.

It doesn't seem to alter what's being tested for Polly (and neither the produced optimised IR). 

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


More information about the llvm-commits mailing list