[LLVMbugs] [Bug 21763] New: [LICM] Loop invariant terminator of loop header can be moved to preheader

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Dec 5 10:31:10 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21763

            Bug ID: 21763
           Summary: [LICM] Loop invariant terminator of loop header can be
                    moved to preheader
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Loop Optimizer
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Given a loop like this:
for(int i = 0; i < N; i++) {
  if(cond) return true;
}
return false;

We currently leave the branch instruction in the loop.  We do this because
there might have been control flow before the branch condition and if so, it
wouldn't be safe to lift the branch.  

However, there's an important case where we can actually lift this.  If the
loop has a preheader, we know that the instructions in the header will execute
exactly when the instructions in the preheader execute.  (The preheader
dominates the header and has a single successor which is the header.)  If the
loop invariant branch is terminating the loop header (and there are no
potentially faulting instructions in that basic block which aren't loop
invariant), we should be able to pull the branch into the loop preheader
(creating a new preheader in the process).  

Currently, we vectorize this loop and create an utter mess of useless IR.  I'm
not sure why, but loop unswitch does not seem to trigger on this loop within
the standard O3 pass ordering.  Invoking it individually does get this case,
but loop unswitching is more heavy weight than is needed here.  There's also an
advantage to be had by interweaving normal LICM and header-terminator-LICM.

-- 
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/20141205/e82ef7ae/attachment.html>


More information about the llvm-bugs mailing list