public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-7721] i386: Don't emit pushf; pop for __builtin_ia32_readeflags_u* with unused lhs [PR104971]
@ 2022-03-19 12:53 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2022-03-19 12:53 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-7721-gb60bc913cca7439d29a7ec9e9a7f448d8841b43c
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-expand.cc
            (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.

Diff:
---
 gcc/config/i386/i386-expand.cc           |  3 +++
 gcc/testsuite/gcc.target/i386/pr104971.c | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index e85641d3204..22728545b83 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -13556,6 +13556,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;
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-03-19 12:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-19 12:53 [gcc r12-7721] i386: Don't emit pushf; pop for __builtin_ia32_readeflags_u* with unused lhs [PR104971] Jakub Jelinek

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).