[llvm-bugs] [Bug 44668] New: [IndVarSimplify] ReplaceExitValue=cheap cost modelling is too pessimistic

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Jan 26 06:44:51 PST 2020


https://bugs.llvm.org/show_bug.cgi?id=44668

            Bug ID: 44668
           Summary: [IndVarSimplify] ReplaceExitValue=cheap cost modelling
                    is too pessimistic
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

Apologies in advance for the crudeness of the "reduced" test case.
I'm providing the full sample for now, to be sure that i don't overreduce it.

https://godbolt.org/z/ZstrDC

If we look at the original IR (see '-lcssa' output), we see:

  <...>
  %10 = load i32, i32* %width, align 8, !tbaa !15
  %16 = zext i32 %10 to i64
; ^ loop-invariant, available before loop entry etc etc
  <...>

for.body:                                         ; preds = %for.body,
%omp.inner.for.body
  %indvars.iv158 = phi i64 [ %indvars.iv.next159, %for.body ], [ 1,
%omp.inner.for.body ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 2,
%omp.inner.for.body ]
  <...>
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %cmp11 = icmp ult i64 %indvars.iv.next, %16
  %indvars.iv.next159 = add nuw nsw i64 %indvars.iv158, 1
  br i1 %cmp11, label %for.body, label %for.cond.invoke.cont15_crit_edge

for.cond.invoke.cont15_crit_edge:                 ; preds = %for.body
  %indvars.iv.lcssa = phi i64 [ %indvars.iv, %for.body ]
  %.lcssa = phi i16 [ %35, %for.body ]
  %conv.i.i.i74.le = sext i16 %.lcssa to i32
  %36 = trunc i64 %indvars.iv.lcssa to i32
  br label %invoke.cont15

invoke.cont15:                                    ; preds =
%for.cond.invoke.cont15_crit_edge, %omp.inner.for.body
  %col.0.lcssa = phi i32 [ %36, %for.cond.invoke.cont15_crit_edge ], [ 1,
%omp.inner.for.body ]
  %idxprom.i.i.i.i72.lcssa = phi i64 [ %indvars.iv.lcssa,
%for.cond.invoke.cont15_crit_edge ], [ 1, %omp.inner.for.body ]
  <...>


So %indvars.iv* is used outside of the loop.
I suspect this is one of the reasons preventing this loop from being
vectorized.

Indeed, IndVarSimplify *can* deal with this, but it doesn't due to costmodel,
with '-lcssa -indvars -replexitval=always', we get the 'expected':

  %10 = load i32, i32* %width, align 8, !tbaa !15
  %16 = zext i32 %10 to i64
  %17 = icmp ugt i64 %16, 3
  %umax = select i1 %17, i64 %16, i64 3
  %18 = add i64 %umax, -1
  <...>

for.body:                                         ; preds =
%for.body.preheader, %for.body
  %indvars.iv158 = phi i64 [ %indvars.iv.next159, %for.body ], [ 1,
%for.body.preheader ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 2,
%for.body.preheader ]
  %29 = add nsw i64 %indvars.iv158, -1
  <...>
  %indvars.iv.next159 = add nuw nsw i64 %indvars.iv158, 1
  br i1 %cmp11, label %for.body, label %for.cond.invoke.cont15_crit_edge

for.cond.invoke.cont15_crit_edge:                 ; preds = %for.body
  %.lcssa = phi i16 [ %37, %for.body ]
  %conv.i.i.i74.le = sext i16 %.lcssa to i32
  %38 = trunc i64 %18 to i32
  br label %invoke.cont15

invoke.cont15:                                    ; preds =
%for.cond.invoke.cont15_crit_edge, %omp.inner.for.body
  %col.0.lcssa = phi i32 [ %38, %for.cond.invoke.cont15_crit_edge ], [ 1,
%omp.inner.for.body ]
  %idxprom.i.i.i.i72.lcssa = phi i64 [ %18, %for.cond.invoke.cont15_crit_edge
], [ 1, %omp.inner.for.body ]


So in old case, in %invoke.cont15 bb, the incoming value for
%col.0.lcssa was essentially %indvars.iv, while now it is %18,
with cost=3 extra instructions.

Is this something fixable in IndVarSimplify?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200126/0fafc05d/attachment.html>


More information about the llvm-bugs mailing list