public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-10140] i386: Don't emit pushf; pop for __builtin_ia32_readeflags_u* with unused lhs [PR104971] Date: Wed, 11 May 2022 06:25:49 +0000 (GMT) [thread overview] Message-ID: <20220511062549.6DF1F3839802@sourceware.org> (raw) 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) Diff: --- gcc/config/i386/i386.c | 3 +++ gcc/testsuite/gcc.target/i386/pr104971.c | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 3f9b092bf58..cb631f7c829 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -37595,6 +37595,9 @@ rdseed_step: return target; case IX86_BUILTIN_READ_FLAGS: + if (ignore) + return const0_rtx; + emit_insn (gen_push (gen_rtx_REG (word_mode, FLAGS_REG))); if (optimize diff --git a/gcc/testsuite/gcc.target/i386/pr104971.c b/gcc/testsuite/gcc.target/i386/pr104971.c new file mode 100644 index 00000000000..80ac6b613f1 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr104971.c @@ -0,0 +1,18 @@ +/* PR middle-end/104971 */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +#include <x86intrin.h> + +__attribute__((noipa)) void +foo (void) +{ + __readeflags (); +} + +int +main () +{ + foo (); + return 0; +}
reply other threads:[~2022-05-11 6:25 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220511062549.6DF1F3839802@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).