On Sat, 2025-11-08 at 00:12 +0100, Martin Jambor wrote:

[...snip...]

> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-3.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-3.c
> new file mode 100644
> index 00000000000..d45928e0a25
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-3.c
> @@ -0,0 +1,30 @@
> +/* { dg-do link } */
> +/* { dg-options "-O2" } */
> +
> +volatile int gi;
> +
> +static const int values[3] = {5, 7, 11};
> +
> +void link_error (void);
> +
> +[[gnu::noinline]] void foo (int index)
> +{
> +  const int v = values[index];
> +  if (v <= 2
> +      || v > 666)

Possibly a silly question, but why "666" here?  Isn't 11 a tighter
bound, based on the values above? (and thus a stronger test case)

> +    link_error ();
> +  else
> +    gi = v;
> +}
> +
> +[[gnu::noipa]] int
> +get_index (void)
> +{
> +  return 1;
> +}
> +
> +int main (int argc, char **argv)
> +{
> +  foo (get_index ());
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-4.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-4.c
> new file mode 100644
> index 00000000000..f0fc8c1f1df
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-4.c
> @@ -0,0 +1,30 @@
> +/* { dg-do link } */
> +/* { dg-options "-O2" } */
> +
> +volatile int gi;
> +
> +static const int values[25] = {5, 7, 11};
> +
> +void link_error (void);
> +
> +[[gnu::noinline]] void foo (int index)
> +{
> +  const int v = values[index];
> +  if (v <= -2
> +      || v > 666)

Likewise.

> +    link_error ();
> +  else
> +    gi = v;
> +}
> +
> +[[gnu::noipa]] int
> +get_index (void)
> +{
> +  return 1;
> +}
> +
> +int main (int argc, char **argv)
> +{
> +  foo (get_index ());
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-5.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-5.c
> new file mode 100644
> index 00000000000..f14e1ee9892
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-5.c
> @@ -0,0 +1,36 @@
> +/* { dg-do link } */
> +/* { dg-options "-O2" } */
> +
> +volatile int gi;
> +
> +static const struct {
> +    int a;
> +    int b;
> +} values[2][2] = {
> +  { {1000, 1 }, {1001, 2} },
> +  { {1003, 1 }, {1004, 2} }
> +};
> +
> +void link_error (void);
> +
> +[[gnu::noinline]] void foo (int i, int j)
> +{
> +  const int v = values[i][j].b;
> +  if (v <= 0
> +      || v > 666)

Likewise - aren't only 1 and 2 valid values of .b,
so can this be (v > 2)?

> +    link_error ();
> +  else
> +    gi = v;
> +}
> +
> +[[gnu::noipa]] int
> +get_index (void)
> +{
> +  return 1;
> +}
> +
> +int main (int argc, char **argv)
> +{
> +  foo (get_index (), get_index ());
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-6.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-6.c
> new file mode 100644
> index 00000000000..0dd6a841f79
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-6.c
> @@ -0,0 +1,42 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +volatile int gi;
> +
> +static const struct {
> +    int a;
> +    int b;
> +} values[2][2] = {
> +  { {0, 1 }, {0, 2} },
> +  { {0, 1 }, {0, 2} }
> +};
> +
> +[[gnu::noipa]] static void
> +check (int v)
> +{
> +  if (!v)
> +    __builtin_abort ();
> +  gi = v;
> +}
> +
> +
> +[[gnu::noinline]] void foo (int i, int j)
> +{
> +  const int v = values[i][j].a;
> +  if (v <= 0
> +      || v > 666)

Likewise, aren't the .a values all 0, so can this be (v != 0) ?

> +    return;
> +  check (v);
> +}
> +
> +[[gnu::noipa]] int
> +get_index (void)
> +{
> +  return 1;
> +}
> +
> +int main (int argc, char **argv)
> +{
> +  foo (get_index (), get_index ());
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-7.c 
> b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-7.c
> new file mode 100644
> index 00000000000..a062aa958b2
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/tree-ssa/vrp-from-cst-agg-7.c
> @@ -0,0 +1,36 @@
> +/* { dg-do link } */
> +/* { dg-options "-O2" } */
> +
> +volatile int gi;
> +
> +static const struct {
> +    int a;
> +    int b;
> +} values[2][2] = {
> +  { {1000, 1 }, {1001, 2} },
> +  { {1003, 1 }, {1004, 2} }
> +};
> +
> +void link_error (void);
> +
> +[[gnu::noinline]] void foo (int i)
> +{
> +  const int v = values[0][i].b;
> +  if (v <= 0
> +      || v > 666)

Likewise; aren't all the .b values 1 or 2, so can this be (v > 2) ?

> +    link_error ();
> +  else
> +    gi = v;
> +}
> +
> +[[gnu::noipa]] int
> +get_index (void)
> +{
> +  return 1;
> +}
> +
> +int main (int argc, char **argv)
> +{
> +  foo (get_index ());
> +  return 0;
> +}

Hope this is constructive
Dave

Reply via email to