On Wed, 2022-05-25 at 10:36 +0200, Richard Biener via Gcc-patches
wrote:
> This patch adds support to unswitch loops with switch statements
> based on invariant index.  It furthermore reworks the cost model
> to allow an overall budget of statements to be created per original
> loop by all unswitching opportunities in the loop.  Compared to
> the original all unswitching opportunities in a loop are
> pre-evaluated before the first transform which will allow future
> changes to select the most profitable candidates first.
> 
> To efficiently support switch statements the pass now uses
> ranger to simplify switch statements and conditions in loop
> copies based on ranges extracted from the recorded set of
> predicates unswitched.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed to trunk.
> 
> Richard.
> 

[...snip...]

> diff --git a/gcc/testsuite/gcc.dg/loop-unswitch-10.c
> b/gcc/testsuite/gcc.dg/loop-unswitch-10.c
> new file mode 100644
> index 00000000000..5e4f16e2935
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/loop-unswitch-10.c
> @@ -0,0 +1,56 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -funswitch-loops -fdump-tree-unswitch-
> optimized" } */
> +
> +int
> +__attribute__((noipa))
> +foo(double *a, double *b, double *c, double *d, double *r, int size,
> int order)
> +{
> +  for (int i = 0; i < size; i++)
> +  {
> +    double tmp, tmp2;
> +
> +    switch(order)
> +    {
> +      case 0:
> +        tmp = -8 * a[i];
> +        tmp2 = 2 * b[i];
> +        break;
> +      case 1: 
> +        tmp = 3 * a[i] -  2 * b[i];
> +        tmp2 = 5 * b[i] - 2 * c[i];
> +        break;
> +      case 2:
> +        tmp = 9 * a[i] +  2 * b[i] + c[i];
> +        tmp2 = 4 * b[i] + 2 * c[i] + 8 * d[i];
> +        break;
> +      case 3:
> +        tmp = 3 * a[i] +  2 * b[i] - c[i];
> +        tmp2 = b[i] - 2 * c[i] + 8 * d[i];
> +        break;
> +      defaut:
> +        __builtin_unreachable ();

I'm guessing "defaut:" here is a typo for "default:" i.e. it's an
unused label named "defaut", when presumably you meant to have an
unreachable default case.  Does this affect the loop unswitching logic?

I wonder if we warn for this (or if we can/should?)

Looking at the patch, it seems to also be present in:
  gcc/testsuite/gcc.dg/loop-unswitch-11.c
  gcc/testsuite/gcc.dg/loop-unswitch-14.c
but I might have missed some.


Dave

Reply via email to