[llvm] r273079 - [SCEV] Fix incorrect trip count computation

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 19 23:25:47 PDT 2016


On Sun, Jun 19, 2016 at 9:43 PM, Sanjoy Das <sanjoy at playingwithpointers.com>
wrote:

> Hi Eli,
>
> Eli Friedman wrote:
> > Sanjoy Das wrote:
> > I'm pretty sure we don't actually do this folding.
>
> Yeah that seemed to be "obvious enough" that I didn't bother checking. :)
>
> In any case, if / once we are able to prove the tripcount of a loop
> is, say, smax(V, V +nsw 10) then teaching getSMax to fold smax(V,
> V +nsw 10) into V +nsw 10 seems like the right layering.
>
> > But there are other issues; we do actually infer nsw in the
> > @nswnowrap testcase, but we can't do anything useful with it because we
> infer it after we build the smax expression.
>
> Are you talking about this case, in nsw.ll ?
>
> define void @nswnowrap(i32 %v) {
> entry:
>   %add = add nsw i32 %v, 1
>   br label %for.body
>
> for.body:
>   %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]
>   %inc = add nsw i32 %i.04, 1
>   tail call void @f(i32 %i.04)
>   %cmp = icmp slt i32 %i.04, %add
>   br i1 %cmp, label %for.body, label %for.end
>
> for.end:
>   ret void
> }
>
>
> ?
>
> Then it does not look like SCEV ever infers `%add` is a nsw-add -- I tried
> `opt -analyze -scalar-evolution -scalar-evolution` and it gave me
>
>   %add = add nsw i32 %v, 1
>   -->  (1 + %v) U: full-set S: full-set
>
> both times.
>

Err, different nswnowrap?  I'm talking about this:

declare void @f(i32)

; CHECK-LABEL: nswnowrap
; CHECK: --> {(1 + %v)<nsw>,+,1}<nsw><%for.body>{{ U: [^ ]+ S: [^ ]+}}{{
*}}Exits: (1 + ((1 + %v)<nsw> smax %v))
define void @nswnowrap(i32 %v, i32* %buf) {
entry:
  %add = add nsw i32 %v, 1
  br label %for.body

for.body:
  %i.04 = phi i32 [ %v, %entry ], [ %inc, %for.body ]
  %inc = add nsw i32 %i.04, 1
  %buf.gep = getelementptr inbounds i32, i32* %buf, i32 %inc
  %buf.val = load i32, i32* %buf.gep
  %cmp = icmp slt i32 %i.04, %add
  tail call void @f(i32 %i.04)
  br i1 %cmp, label %for.body, label %for.end

for.end:
  ret void
}

The expression "((1 + %v)<nsw> smax %v)" shows up in the computed exit
values, but doesn't get simplified.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160619/47e648e6/attachment.html>


More information about the llvm-commits mailing list