[Bug middle-end/104971] [9/10 Regression] Optimisation for __builtin_ia32_readeflags corrupts the stack

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed May 11 06:25:50 GMT 2022


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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-9 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:c1a8261b7054da31420e5c715e682c1b42e473b5

commit r9-10140-gc1a8261b7054da31420e5c715e682c1b42e473b5
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Mar 19 13:53:12 2022 +0100

    i386: Don't emit pushf;pop for __builtin_ia32_readeflags_u* with unused lhs
[PR104971]

    __builtin_ia32_readeflags_u* aren't marked const or pure I think
    intentionally, so that they aren't CSEd from different regions of a
function
    etc. because we don't and can't easily track all dependencies between
    it and surrounding code (if somebody looks at the condition flags, it is
    dependent on the vast majority of instructions).
    But the builtin itself doesn't have any side-effects, so if we ignore the
    result of the builtin, there is no point to emit anything.

    There is a LRA bug that miscompiles the testcase which this patch makes
    latent, which is certainly worth fixing too, but IMHO this change
    (and maybe ix86_gimple_fold_builtin too which would fold it even earlier
    when it looses lhs) is worth it as well.

    2022-03-19  Jakub Jelinek  <jakub@redhat.com>

            PR middle-end/104971
            * config/i386/i386.c
            (ix86_expand_builtin) <case IX86_BUILTIN_READ_FLAGS>: If ignore,
            don't push/pop anything and just return const0_rtx.

            * gcc.target/i386/pr104971.c: New test.

    (cherry picked from commit b60bc913cca7439d29a7ec9e9a7f448d8841b43c)


More information about the Gcc-bugs mailing list