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

            Bug ID: 126109
           Summary: cselim could better handle maybe non-trapping
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
struct f
{
  int t[16];
  int m;
};
struct f arr;

int bitset2 (int n, int b)
{
  if (n >= 16)  __builtin_unreachable ();
  int bit = 0x4;
  //arr.t[n] = b;
  if ((arr.t[n] & bit) == 0)
    arr.t[n] |= bit;

  return arr.t[n];
}
```
With `-O2 -fallow-store-data-races`.

Currently cselim uses tree_could_trap_p; tree_could_trap_p calls
in_array_bounds_p but that only handles INTEGER_CSTs and does not look at the
range of n here.

With https://gcc.gnu.org/pipermail/gcc-patches/2026-July/722737.html, we can
improve the call to tree_could_trap_p to take into account that the range of
the index here at the statements we are checking even.

Note I am not sure we want to always have tree_could_trap_p look into the range
either.

Reply via email to