public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Richard Biener <rguenther@suse.de>, Jeff Law <jeffreyalaw@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Roger Sayle <roger@nextmovesoftware.com>
Subject: [PATCH] simplify-rtx: Fix up SUBREG_PROMOTED_SET arguments [PR104839]
Date: Tue, 8 Mar 2022 16:56:50 +0100	[thread overview]
Message-ID: <Yid8wgCHyfeNUbg+@tucnak> (raw)

Hi!

The following testcase is miscompiled on powerpc64le-linux at -O1 and higher
(except for -Og).  The bug was introduced in r12-3252-gcad36f38576a6a7
which for SIGN_EXTEND from SUBREG_PROMOTED_SIGNED_P SUBREG used
SUBREG_PROMOTED_SET (temp, 1) (but that makes temp
SUBREG_PROMOTED_UNSIGNED_P because SRP_UNSIGNED is 1) and similarly the
ZERO_EXTEND from SUBREG_PROMOTED_UNSIGNED_P SUBREG used
SUBREG_PROMOTED_SET (temp, 0) (but that makes temp
SUBREG_PROMOTED_SIGNED_P because SRP_SIGNED is 0).
The following patch fixes that (swaps the 0s and 1s), but for better
readability uses the SRP_* constants.
rtl.h has:
/* Valid for subregs which are SUBREG_PROMOTED_VAR_P().  In that case
   this gives the necessary extensions:
   0  - signed (SPR_SIGNED)
   1  - normal unsigned (SPR_UNSIGNED)
   2  - value is both sign and unsign extended for mode
        (SPR_SIGNED_AND_UNSIGNED).
   -1 - pointer unsigned, which most often can be handled like unsigned
        extension, except for generating instructions where we need to
        emit special code (ptr_extend insns) on some architectures
        (SPR_POINTER). */
The expr.c change in the same commit looks ok to me (passes unsignedp
to SUBREG_PROMOTED_SET, so 0 for signed, 1 for unsigned).

Starting bootstrap/regtest on powerpc64{,le}-linux now, ok for trunk?

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

	PR rtl-optimization/104839
	* simplify-rtx.cc (simplify_unary_operation_1) <case SIGN_EXTEND>:
	Use SRP_SIGNED instead of incorrect 1 in SUBREG_PROMOTED_SET.
	(simplify_unary_operation_1) <case ZERO_EXTEND>: Use SRP_UNSIGNED
	instead of incorrect 0 in SUBREG_PROMOTED_SET.

	* gcc.c-torture/execute/pr104839.c: New test.

--- gcc/simplify-rtx.cc.jj	2022-02-23 09:17:04.000000000 +0100
+++ gcc/simplify-rtx.cc	2022-03-08 16:31:20.823246404 +0100
@@ -1527,7 +1527,7 @@ simplify_context::simplify_unary_operati
 		  if (partial_subreg_p (temp))
 		    {
 		      SUBREG_PROMOTED_VAR_P (temp) = 1;
-		      SUBREG_PROMOTED_SET (temp, 1);
+		      SUBREG_PROMOTED_SET (temp, SRP_SIGNED);
 		    }
 		  return temp;
 		}
@@ -1662,7 +1662,7 @@ simplify_context::simplify_unary_operati
 		  if (partial_subreg_p (temp))
 		    {
 		      SUBREG_PROMOTED_VAR_P (temp) = 1;
-		      SUBREG_PROMOTED_SET (temp, 0);
+		      SUBREG_PROMOTED_SET (temp, SRP_UNSIGNED);
 		    }
 		  return temp;
 		}
--- gcc/testsuite/gcc.c-torture/execute/pr104839.c.jj	2022-03-08 16:46:51.418440078 +0100
+++ gcc/testsuite/gcc.c-torture/execute/pr104839.c	2022-03-08 16:46:27.044774203 +0100
@@ -0,0 +1,37 @@
+/* PR rtl-optimization/104839 */
+
+__attribute__((noipa)) short
+foo (void)
+{
+  return -1;
+}
+
+__attribute__((noipa)) int
+bar (void)
+{
+  short i = foo ();
+  if (i == -2)
+    return 2;
+  long k = i;
+  int j = -1;
+  volatile long s = 300;
+  if (k < 0)
+    {
+      k += s;
+      if (k < 0)
+	j = 0;
+    }
+  else if (k >= s)
+    j = 0;
+  if (j != -1)
+    return 1;
+  return 0;
+}
+
+int
+main ()
+{
+  if (bar () != 0)
+    __builtin_abort ();
+  return 0;
+}

	Jakub


             reply	other threads:[~2022-03-08 15:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 15:56 Jakub Jelinek [this message]
2022-03-09  7:15 ` Richard Biener

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=Yid8wgCHyfeNUbg+@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.com \
    --cc=rguenther@suse.de \
    --cc=roger@nextmovesoftware.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).