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

--- Comment #9 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Indeed volatile checks seems to be missing across ipa-prop code. Here is
smaller testcase:

__attribute__((noinline))
static int
test2(int a)
{
        if (__builtin_constant_p (a))
                __builtin_abort ();
        return a;
}
/*__attribute__((noinline))*/
static int
test(int *a)
{
        int val = *(volatile int *)a;
        if (__builtin_constant_p (val))
                __builtin_abort ();
        if (val)
          return test2(val);
        return 0;
}
int a;
int
main()
{
        a = 0;
        return test (&a);
}

is optimized to
main:
.LFB2:
        .cfi_startproc
        movl    $0, a(%rip)
        movl    a(%rip), %eax
        xorl    %eax, %eax
        ret
        .cfi_endproc

which I don't think is correct. The volatile load can be non-0 and thus we can
return non-0.
It does not trigger unreachable as I hoped for since vrp and fab passes seems
to jump to same conclusion as ipa-cp.

Reply via email to