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 r12-8224] rtlanal: Fix up replace_rtx [PR105333]
Date: Fri, 22 Apr 2022 11:38:49 +0000 (GMT)	[thread overview]
Message-ID: <20220422113849.CCB04385843E@sourceware.org> (raw)

https://gcc.gnu.org/g:7092b7aea122a91824d048aeb23834cf1d19b1a1

commit r12-8224-g7092b7aea122a91824d048aeb23834cf1d19b1a1
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 22 13:38:11 2022 +0200

    rtlanal: Fix up replace_rtx [PR105333]
    
    The following testcase FAILs, because replace_rtx replaces a REG with
    CONST_WIDE_INT inside of a SUBREG, which is an invalid transformation
    because a SUBREG relies on SUBREG_REG having non-VOIDmode but
    CONST_WIDE_INT has VOIDmode.
    
    replace_rtx already has code to deal with it, but it was doing
    it only for CONST_INTs.  The following patch does it also for
    VOIDmode CONST_DOUBLE or CONST_WIDE_INT.
    
    2022-04-22  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/105333
            * rtlanal.cc (replace_rtx): Use simplify_subreg or
            simplify_unary_operation if CONST_SCALAR_INT_P rather than just
            CONST_INT_P.
    
            * gcc.dg/pr105333.c: New test.

Diff:
---
 gcc/rtlanal.cc                  |  4 ++--
 gcc/testsuite/gcc.dg/pr105333.c | 21 +++++++++++++++++++++
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/gcc/rtlanal.cc b/gcc/rtlanal.cc
index e1824bfefb7..c436c640c37 100644
--- a/gcc/rtlanal.cc
+++ b/gcc/rtlanal.cc
@@ -3390,7 +3390,7 @@ replace_rtx (rtx x, rtx from, rtx to, bool all_regs)
     {
       rtx new_rtx = replace_rtx (SUBREG_REG (x), from, to, all_regs);
 
-      if (CONST_INT_P (new_rtx))
+      if (CONST_SCALAR_INT_P (new_rtx))
 	{
 	  x = simplify_subreg (GET_MODE (x), new_rtx,
 			       GET_MODE (SUBREG_REG (x)),
@@ -3406,7 +3406,7 @@ replace_rtx (rtx x, rtx from, rtx to, bool all_regs)
     {
       rtx new_rtx = replace_rtx (XEXP (x, 0), from, to, all_regs);
 
-      if (CONST_INT_P (new_rtx))
+      if (CONST_SCALAR_INT_P (new_rtx))
 	{
 	  x = simplify_unary_operation (ZERO_EXTEND, GET_MODE (x),
 					new_rtx, GET_MODE (XEXP (x, 0)));
diff --git a/gcc/testsuite/gcc.dg/pr105333.c b/gcc/testsuite/gcc.dg/pr105333.c
new file mode 100644
index 00000000000..bd8bd4cd56c
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr105333.c
@@ -0,0 +1,21 @@
+/* PR rtl-optimization/105333 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-Og -fno-tree-coalesce-vars -fno-tree-fre" } */
+
+int g;
+short s;
+
+static inline unsigned short
+bar (short a, __int128 b)
+{
+  b ^= (unsigned long) -a;
+  __builtin_strncpy ((void *) &s, (void *) &a, 1);
+  b *= 14;
+  return b;
+}
+
+void
+foo (void)
+{
+  g *= (__int128) bar (1, 1);
+}


                 reply	other threads:[~2022-04-22 11:38 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=20220422113849.CCB04385843E@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: 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).