diff mbox series

tree-ssa-math-opts: Fix up ICE in match_uaddc_usubc [PR110508]

Message ID ZKGPdiAZUtNk3yqa@tucnak
State New
Headers show
Series tree-ssa-math-opts: Fix up ICE in match_uaddc_usubc [PR110508] | expand

Commit Message

Jakub Jelinek July 2, 2023, 2:53 p.m. UTC
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.


	Jakub

Comments

Richard Biener July 2, 2023, 3:23 p.m. UTC | #1
> Am 02.07.2023 um 16:54 schrieb Jakub Jelinek via Gcc-patches <gcc-patches@gcc.gnu.org>:
> 
> 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?

Ok

Richard 

> 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
>
diff mbox series

Patch

--- 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);
+}