[llvm-bugs] [Bug 28272] New: LoopSimplify does not preserve LCSSA when separating nested loops.

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 22 18:31:14 PDT 2016


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

            Bug ID: 28272
           Summary: LoopSimplify does not preserve LCSSA when separating
                    nested loops.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: michael.v.zolotukhin at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following testcase fails with an assertion:
> opt -lcssa -loop-unroll -o - -S < test.ll
Assertion failed: (InLCSSA && "LCSSA is broken after loop-simplify."), function
runOnFunction, file
/Users/mvzolotu/devel/llvm.git/lib/Transforms/Utils/LoopSimplify.cpp, line 803.
Stack dump:
0.    Program arguments: bin/opt -lcssa -loop-unroll -o - -S
1.    Running pass 'Function Pass Manager' on module '<stdin>'.
2.    Running pass 'Canonicalize natural loops' on function '@func_10'

> cat test.ll
target triple = "x86_64-unknown-linux-gnu"

define void @func_10() {
entry:
  br label %bb29

bb29:
  br label %bb40

bb40:
  br i1 true, label %bb40, label %bb43

bb43:
  %a = phi i32 [ undef, %bb40 ], [ 0, %bb45 ], [ %a, %bb54 ]
  %b = phi i32 [ 0, %bb40 ], [ 1, %bb54 ], [ %c, %bb45 ]
  br i1 true, label %bb114, label %bb29

bb114:
  %c = add i32 0, 1
  br i1 true, label %bb45, label %bb54

bb45:
  br label %bb43

bb54:
  br label %bb43
}

This started to happen after r272224, where the assertion was added.

The bug seems to be in routine separateNestedLoop (in LoopSimplify.cpp). When
we split the loop header, we use SplitBlockPredecessors from
BasicBlockUtils.cpp. The latter function is supposed to preserve LCSSA, but in
our case splitting the block creates a new loop. Thus, loop info is no longer
valid, but SplitBlockPredecessors relies on it.

There are several possible fixes here:
1) Don't try to preserve LCSSA in the process and just recompute it when we're
finished separating the nested loops.
2) Don't pass LoopInfo to the basic blocks utils at all (thus not pretending
that we're preserving LCSSA). Then update LCSSA in separateNestedLoop manually.
Also, we might want to add an assert to SplitBlockPredecessors that we're not
splitting a loop header, since it breaks LCSSA.
3) Move logic for updating LoopInfo from separateNestedLoop to
SplitBlockPredecessors, teaching it to recognize cases where splitting a block
creates a loop and to handle such cases properly.

Option (3) looks the best to me, but if anyone is blocked, they can use (1) as
a workaround, as it's a one-line change.

-- 
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/20160623/cf739ef3/attachment.html>


More information about the llvm-bugs mailing list