[LLVMbugs] [Bug 2118] New: Loop Optimizer Problems

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sun Mar 2 11:47:44 PST 2008

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

Summary: Loop Optimizer Problems
Product: libraries
Version: 2.2
Platform: PC
OS/Version: All
Status: NEW
Keywords: code-quality, slow-compile
Severity: normal
Priority: P2
Component: Loop Optimizer
AssignedTo: unassignedbugs at nondot.org
ReportedBy: sabre at nondot.org
CC: llvmbugs at cs.uiuc.edu

Consider this code:
void test(double vertices[][3], double KeKe[][12], double Me[], double
jacobian[3][3]) {
double ds[3][4];
double sum[3];
double det;
double volume;
double E, nu;
double c1, c2, c3;
double tt, ts;
int i, j, m, n, row, column;
shape_ders(ds);
i = 0;
for (j = 0; j < 3; j++) {
double sum = 0.0;
for (m = 0; m < 4; m++)
sum = sum + ds[i][m] * vertices[m][j];
jacobian[j][i] = sum;         /* compute Jacobian */
}
}

When compiled with llvm-gcc, there are loads of ds that are left in the loop.
Peeling the inner loop means that the loads are all from LIV indices and could
be hoisted.  This is a problem, however, this points out other problems.  I've
attached a bc file from right before the loop optimizer.  The loop optimizer
consists of:

\$opt loop_test.bc -loopsimplify -loop-rotate -licm -loop-unswitch
-loop-index-split -instcombine -indvars -loop-unroll

When you run this with -debug-pass=Executions, it becomes clear that LCSSA is
being rerun before each pass, this is very bad.  Do the loop passes need to
explicitly state that they preserve LCSSA?

0xc031a8     Executing Pass 'Loop Pass Manager' on Function
'element_matrices'...
0xc04028       Executing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028       Executing Pass 'Index Split Loops' on Loop '...
0xc04028        Freeing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028        Freeing Pass 'Index Split Loops' on Loop '...
0xc04028       Executing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028       Executing Pass 'Index Split Loops' on Loop '...
0xc04028        Freeing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028        Freeing Pass 'Index Split Loops' on Loop '...
0xc04028       Executing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028       Executing Pass 'Index Split Loops' on Loop '...
0xc04028        Freeing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028        Freeing Pass 'Index Split Loops' on Loop '...
0xc04028       Executing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028       Executing Pass 'Index Split Loops' on Loop '...
0xc04028        Freeing Pass 'Loop-Closed SSA Form Pass' on Loop '...
0xc04028        Freeing Pass 'Index Split Loops' on Loop '...

Also, the 'not hoisting after unrolling' is an apparent failure of the new
LoopPassManager or a problem with the pass ordering in .  All these loop
optimizations should be run on the inner loop first (which unrolls it) then on
the outer loop (which can hoist the loads).

-Chris

--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

```