void bar(int, int, int); void foo(int left, int rite, int element) { while (left <= rite) { rite -= element; bar(left, rite, element); left += element; } }
produces: foo (int left, int rite, int element) { unsigned int D.2741; unsigned int D.2742; unsigned int D.2743; unsigned int D.2737; int D.2738; unsigned int D.2739; unsigned int D.2740; <bb 2>: if (left_3(D) <= rite_4(D)) goto <bb 3>; else goto <bb 6>; <bb 3>: <bb 4>: # left_14 = PHI <left_7(5), left_3(D)(3)> # rite_15 = PHI <rite_6(5), rite_4(D)(3)> D.2737_8 = (unsigned int) rite_15; D.2738_2 = -element_5(D); D.2739_1 = (unsigned int) D.2738_2; D.2740_13 = D.2737_8 + D.2739_1; rite_12 = (int) D.2740_13; rite_6 = rite_12; bar (left_14, rite_6, element_5(D)); D.2741_11 = (unsigned int) left_14; D.2742_17 = (unsigned int) element_5(D); D.2743_18 = D.2741_11 + D.2742_17; left_19 = (int) D.2743_18; left_7 = left_19; if (rite_6 >= left_7) goto <bb 5>; else goto <bb 6>; <bb 5>: goto <bb 4>; from foo (int left, int rite, int element) { <bb 2>: if (left_3(D) <= rite_4(D)) goto <bb 3>; else goto <bb 6>; <bb 3>: <bb 4>: # left_14 = PHI <left_7(5), left_3(D)(3)> # rite_15 = PHI <rite_6(5), rite_4(D)(3)> rite_6 = rite_15 - element_5(D); bar (left_14, rite_6, element_5(D)); left_7 = left_14 + element_5(D); if (rite_6 >= left_7) goto <bb 5>; else goto <bb 6>; <bb 5>: goto <bb 4>; as you can see it doesn't even create new induction variables. -- Summary: IVOPTs messes up code Product: gcc Version: 4.5.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: rguenth at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43378