public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Greg McGary <gkm@rivosinc.com>
To: gcc-patches@gcc.gnu.org, Greg McGary <greg.mcgary@gmail.com>
Cc: Greg McGary <gkm@rivosinc.com>
Subject: [PATCH] combine: Don't optimize SIGN_EXTEND of MEM on WORD_REGISTER_OPERATIONS targets [PR113010]
Date: Tue, 16 Jan 2024 14:19:14 -0800	[thread overview]
Message-ID: <20240116221914.267015-1-gkm@rivosinc.com> (raw)

The sign bit of a sign-extending load cannot be known until runtime,
so don't attempt to simplify it in the combiner.

2024-01-11  Greg McGary  <gkm@rivosinc.com>

        PR rtl-optimization/113010
        * combine.cc (expand_compound_operation): Don't simplify
	SIGN_EXTEND of a MEM on WORD_REGISTER_OPERATIONS targets

        * gcc.c-torture/execute/pr113010.c: New test.
---
 gcc/combine.cc                                 | 5 +++++
 gcc/testsuite/gcc.c-torture/execute/pr113010.c | 9 +++++++++
 2 files changed, 14 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr113010.c

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 812553c091e..ba587184dfc 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -7208,6 +7208,11 @@ expand_compound_operation (rtx x)
       if (len == 0)
 	return x;
 
+      /* Sign-extending loads can never be simplified at compile time.  */
+      if (WORD_REGISTER_OPERATIONS && MEM_P (XEXP (x, 0))
+	  && load_extend_op (inner_mode) == SIGN_EXTEND)
+	return x;
+
       break;
 
     case ZERO_EXTRACT:
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr113010.c b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
new file mode 100644
index 00000000000..a95c613c1df
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr113010.c
@@ -0,0 +1,9 @@
+int minus_1 = -1;
+
+int
+main ()
+{
+  if ((0, 0xfffffffful) >= minus_1)
+    __builtin_abort ();
+  return 0;
+}
-- 
2.34.1


             reply	other threads:[~2024-01-16 22:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-16 22:19 Greg McGary [this message]
2024-01-17  6:44 ` Richard Biener
2024-01-18  3:53   ` Greg McGary
2024-01-18 16:24     ` Jeff Law
2024-02-02  1:24       ` Greg McGary
2024-02-02  5:24         ` Jeff Law
2024-02-02 22:48           ` Greg McGary
2024-02-05  4:58             ` Jeff Law
2024-02-08  5:36               ` Greg McGary
2024-01-17  7:56 ` YunQiang Su

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=20240116221914.267015-1-gkm@rivosinc.com \
    --to=gkm@rivosinc.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=greg.mcgary@gmail.com \
    /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: link
Be 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).