[PATCH] Fix PR tree-opt/17343, cases do not combine with default

Andrew Pinski pinskia@physics.uc.edu
Fri Oct 1 14:44:00 GMT 2004


On Oct 1, 2004, at 1:19 AM, Andrew Pinski wrote:

> I decided to look into some regressions for 4.0.0 and I noticed this
> one.  I decided to look into this bug and fix this one.  It was an easy
> one to fix as the intent to do this optimization was here but some
> how was messed up for some reason (I did not look into why).

What was going on was that default_label was pointing to a
CASE_LABEL_EXPR instead of the LABEL_DECL for default case
which means that we will never match the default case and never
merge any other case statement with it at all.

The testcase looks like:

void
foo (int a)
{
   switch (a)
     {
     case 10:
     case 11:
     case 12:
     case 13:
       goto ddd;
     case 14:
       foo1();
       break;
     case 15:
       foo2();
       break;
     case 16:
       foo3();
       break;
     default:
     ddd:
       foo0();
       break;
     }
}

but since we would not merge case 10 ... 13 with the default case we
ended up with less than optimal code when we came to expand it.

Before my patch:
_foo:
         addi r0,r3,-10
         cmplwi cr7,r0,6
         bgt- cr7,L2
         lis r2,ha16(L6)
         slwi r0,r0,2
         la r2,lo16(L6)(r2)
         lwzx r9,r2,r0
         add r9,r9,r2
         mtctr r9
         bctr
         .align 2
L6:
         .long L2-L6
         .long L2-L6
         .long L2-L6
         .long L2-L6
         .long L3-L6
         .long L4-L6
         .long L5-L6
L2:
         b _foo0
L5:
         b _foo3
L3:
         b _foo1
L4:
         b _foo2

After:
_foo:
         cmpwi cr7,r3,15
         cmpwi cr6,r3,16
         beq- cr7,L4
         cmpwi cr7,r3,14
         beq- cr6,L5
         beq- cr7,L9
L2:
         b _foo0
L4:
         b _foo2
L5:
         b _foo3
L9:
         b _foo1

And we used to get the after with 3.4.0.


Thanks,
Andrew Pinski



More information about the Gcc-patches mailing list