[llvm-bugs] [Bug 27360] LLVM fails to unroll multi-exit loops with multiple exiting blocks jumping to the same exit block and runtime trip count

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Mar 24 10:41:52 PDT 2020


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

Florian Hahn <florian_hahn at apple.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
            Summary|LLVM cannot unroll loops    |LLVM fails to unroll
                   |with multiple exits         |multi-exit loops with
                   |                            |multiple exiting blocks
                   |                            |jumping to the same exit
                   |                            |block and runtime trip
                   |                            |count
         Resolution|FIXED                       |---

--- Comment #3 from Florian Hahn <florian_hahn at apple.com> ---
Ok, turns out that without the pragma, multi-exit unrolling is not happing, due
to a TODO in LoopUnrollRuntime.cpp. I am re-opening the issue to address that:

  // TODO: Support multiple exiting blocks jumping to the `LatchExit` when
  // UnrollRuntimeMultiExit is true. This will need updating the logic in
  // connectEpilog/connectProlog.
  if (!LatchExit->getSinglePredecessor()) {



Below the IR for the example at hand. @multi_exit_runtime_trip_count is not
unrolled even with -unroll-runtime -unroll-runtime-multi-exit, due to the TODO.
@unroll_latch_count_known is unrolled with -unroll-allow-partial.




define i1 @multi_exit_runtime_trip_count(i32 %i, i32* %m) {
entry:
  %0 = sext i32 %i to i64
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ %0, %entry ]
  %w.0.in = getelementptr inbounds i32, i32* %m, i64 %indvars.iv
  %w.0 = load i32, i32* %w.0.in, align 4
  %cmp = icmp eq i32 %w.0, 0
  br i1 %cmp, label %while.body, label %cleanup

while.body:                                       ; preds = %while.cond
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %cmp1 = icmp slt i64 %indvars.iv, 1
  br i1 %cmp1, label %cleanup, label %while.cond

cleanup:                                          ; preds = %while.cond,
%while.body
  %retval.0 = phi i1 [ false, %while.body ], [ true, %while.cond ]
  ret i1 %retval.0
}


define i1 @unroll_latch_count_known(i32 %i, i32* %m) {
entry:
  %0 = sext i32 %i to i64
  br label %while.cond

while.cond:                                       ; preds = %while.body, %entry
  %indvars.iv = phi i64 [ %indvars.iv.next, %while.body ], [ 0, %entry ]
  %w.0.in = getelementptr inbounds i32, i32* %m, i64 %indvars.iv
  %w.0 = load i32, i32* %w.0.in, align 4
  %cmp = icmp eq i32 %w.0, 0
  br i1 %cmp, label %while.body, label %cleanup

while.body:                                       ; preds = %while.cond
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %cmp1 = icmp eq i64 %indvars.iv, 999
  br i1 %cmp1, label %cleanup, label %while.cond

cleanup:                                          ; preds = %while.cond,
%while.body
  %retval.0 = phi i1 [ false, %while.body ], [ true, %while.cond ]
  ret i1 %retval.0
}

-- 
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/20200324/5fcd7ba0/attachment.html>


More information about the llvm-bugs mailing list