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

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 19 21:43:53 PDT 2016

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) {
   %add = add nsw i32 %v, 1
   br label %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

   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.

-- Sanjoy

More information about the llvm-commits mailing list