https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106783
--- Comment #8 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
(In reply to Jan Hubicka from comment #6)
> The problem is that n/=0 is undefined behavior (so we can optimize out call
> to function doing divide by zero), while __builtin_trap is observable and we
> do not optimize out code paths that may trip to it.
>
Hmmmm I hit this today with:
void foo1 (char *restrict a, int *restrict c, int n, int stride)
{
if (stride <= 1)
return;
for (int i = 0; i < 9; i++)
{
int res = c[i];
c[i] = a[i] ? res : 9;
}
}
compiled with -Ofast -march=armv9-a -fdump-tree-modref.
At least this variant has no builtin traps (nor UB).
See https://godbolt.org/z/1h83rasns