https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127879

            Bug ID: 127879
           Summary: Improve fold_using_range::range_from_readonly_var for
                    STRING_CSTs and RAW_DATA_CST
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
  Target Milestone: ---

const unsigned char a[] = { 100, 108, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
0, 24, 18, 35, 98 };
const unsigned char b[] = { 100, 108, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57,
                            0, 24, 18, 35, 98 };
const struct { int a; unsigned char b; } c[] = { { 0, 100 }, { 0, 108 }, { 0,
48 }, { 0, 49 }, { 0, 50 }, { 0, 51 },
                                                 { 0, 52 }, { 0, 53 }, { 0, 54
}, { 0, 55 }, { 0, 56 }, { 0, 57 },
                                                 { 0, 0 }, { 0, 24 }, { 0, 18
}, { 0, 35 }, { 0, 98 } };

int
foo (int x)
{
  if (x < 2 || x >= 12)
    return -1;
  if (a[x] >= 48 && a[x] <= 57)
    return 1;
  return 0;
}

int
bar (int x)
{
  if (x < 2 || x >= 220)
    return -1;
  if (b[x] >= 48 && b[x] <= 57)
    return 1;
  return 0;
}

int
baz (int x)
{
  if (x < 2 || x >= 12)
    return -1;
  if (c[x].b >= 48 && c[x].b <= 57)
    return 1;
  return 0;
}
with -O2 --param vrp-cstload-limit=255 optimizes just baz into return x + 2U >=
14U ? -1 : 1; and doesn't optimize foo nor bar.
For foo, braced_list_to_string optimizes the CONSTRUCTOR into a STRING_CST
(and, it can appear both as toplevel thing from fold_ctor_reference or just its
part), for bar it gives up on RAW_DATA_CST.

Will try to handle this tomorrow.

Reply via email to