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>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] tree-ssa-math-opts: Fix up ICE in match_uaddc_usubc [PR110508]
Date: Sun, 2 Jul 2023 16:53:42 +0200	[thread overview]
Message-ID: <ZKGPdiAZUtNk3yqa@tucnak> (raw)

Hi!

The match_uaddc_usubc matching doesn't require that the second
.{ADD,SUB}_OVERFLOW has REALPART_EXPR of its lhs used, only that there is
at most one.  So, in the weird case where the REALPART_EXPR of it isn't
present, we shouldn't ICE trying to replace that REALPART_EXPR with
REALPART_EXPR of .U{ADD,SUB}C result.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-07-02  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/110508
	* tree-ssa-math-opts.cc (match_uaddc_usubc): Only replace re2 with
	REALPART_EXPR opf nlhs if re2 is non-NULL.

	* gcc.dg/pr110508.c: New test.

--- gcc/tree-ssa-math-opts.cc.jj	2023-06-20 11:22:26.726887276 +0200
+++ gcc/tree-ssa-math-opts.cc	2023-07-01 00:29:48.554230914 +0200
@@ -4856,11 +4856,14 @@ match_uaddc_usubc (gimple_stmt_iterator
   gsi_remove (&gsi2, true);
   /* Replace the re2 statement with __real__ of the newly added
      .UADDC/.USUBC call.  */
-  gsi2 = gsi_for_stmt (re2);
-  tree rlhs = gimple_assign_lhs (re2);
-  g = gimple_build_assign (rlhs, REALPART_EXPR,
-			   build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs));
-  gsi_replace (&gsi2, g, true);
+  if (re2)
+    {
+      gsi2 = gsi_for_stmt (re2);
+      tree rlhs = gimple_assign_lhs (re2);
+      g = gimple_build_assign (rlhs, REALPART_EXPR,
+			       build1 (REALPART_EXPR, TREE_TYPE (rlhs), nlhs));
+      gsi_replace (&gsi2, g, true);
+    }
   if (rhs[2])
     {
       /* If this is the arg1 + arg2 + (ovf1 + ovf2) or
--- gcc/testsuite/gcc.dg/pr110508.c.jj	2023-07-01 00:33:12.494405901 +0200
+++ gcc/testsuite/gcc.dg/pr110508.c	2023-07-01 00:32:24.115075870 +0200
@@ -0,0 +1,9 @@
+/* PR tree-optimization/110508 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+void
+foo (unsigned a, unsigned b, unsigned *c, _Bool d)
+{
+  __builtin_addc (a, b, d, c);
+}

	Jakub


             reply	other threads:[~2023-07-02 14:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-02 14:53 Jakub Jelinek [this message]
2023-07-02 15:23 ` 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=ZKGPdiAZUtNk3yqa@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rguenther@suse.de \
    /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).