New pass manager is populating loops in forward program order rather than legacy pass manager.
Let's see a worse case with the order of new loop pass manager as below.
loop1: %6 = phi i8 [ 0, %1 ], [ %9, %5 ] %7 = phi i32 [ 1, %ph ], [ %8, %loop1 ] %8 = add nuw nsw i8 %7, 1 %9 = select i1 %4, i8 1, i8 %6 %10 = and i8 %9, %11 = icmp eq i32 %10, 0 br i1 %11, label %loop1, label %ph2 ph2: %13 = phi i32 [ %8, %loop1 ] br label %14 loop2: %15 = phi i32 [ %16, %loop2 ], [ %13, %ph2 ] %16 = add nsw i32 %15, -1 %17 = icmp sgt i32 %15, 0 br i1 %17, label %14, label %exit ... }
The loop2 is read-only loop and the IndVarSimplify pass can delete the loop. If we use reverse program order of loops, the loop2 can be deleted and it causes loop1 is also redundant because %8 has no use any more. If we use forward program order of loops, the loop1 can not be removed because the loop2 uses %8 during optimizing loop1.
This change populates the loops in reverse program order on new pass manager like legacy pass manager.
this is now wrong?