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 r11-10717] cfgexpand: Handle WIDEN_{PLUS, MINUS}_EXPR and VEC_WIDEN_{PLUS, MINUS}_{HI, LO}_EXPR in expand_debug_ex
Date: Tue,  2 May 2023 20:15:10 +0000 (GMT)	[thread overview]
Message-ID: <20230502201510.C23E438A9087@sourceware.org> (raw)

https://gcc.gnu.org/g:54b240621d372e63d8fcacae591e39b36634ac18

commit r11-10717-g54b240621d372e63d8fcacae591e39b36634ac18
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Mar 1 10:26:46 2023 +0100

    cfgexpand: Handle WIDEN_{PLUS,MINUS}_EXPR and VEC_WIDEN_{PLUS,MINUS}_{HI,LO}_EXPR in expand_debug_expr [PR108967]
    
    When these tree codes were introduced, expand_debug_expr hasn't been
    updated to handle them.  For the VEC_*_EXPR we currently mostly punt, the
    non-vector ones can be handled easily.  In release compilers this doesn't
    ICE, but with checking we ICE so that we make sure to handle all the needed
    tree codes there.
    
    2023-03-01  Jakub Jelinek  <jakub@redhat.com>
    
            PR debug/108967
            * cfgexpand.c (expand_debug_expr): Handle WIDEN_{PLUS,MINUS}_EXPR
            and VEC_WIDEN_{PLUS,MINUS}_{HI,LO}_EXPR.
    
            * g++.dg/debug/pr108967.C: New test.
    
    (cherry picked from commit 520403f324a6ed8b527f39239709dd0841b992e2)

Diff:
---
 gcc/cfgexpand.c                       | 10 +++++++++
 gcc/testsuite/g++.dg/debug/pr108967.C | 41 +++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c
index 3c1fe867bd3..a607ad50d2b 100644
--- a/gcc/cfgexpand.c
+++ b/gcc/cfgexpand.c
@@ -5356,6 +5356,10 @@ expand_debug_expr (tree exp)
     case VEC_WIDEN_MULT_ODD_EXPR:
     case VEC_WIDEN_LSHIFT_HI_EXPR:
     case VEC_WIDEN_LSHIFT_LO_EXPR:
+    case VEC_WIDEN_PLUS_HI_EXPR:
+    case VEC_WIDEN_PLUS_LO_EXPR:
+    case VEC_WIDEN_MINUS_HI_EXPR:
+    case VEC_WIDEN_MINUS_LO_EXPR:
     case VEC_PERM_EXPR:
     case VEC_DUPLICATE_EXPR:
     case VEC_SERIES_EXPR:
@@ -5392,6 +5396,8 @@ expand_debug_expr (tree exp)
     case WIDEN_MULT_EXPR:
     case WIDEN_MULT_PLUS_EXPR:
     case WIDEN_MULT_MINUS_EXPR:
+    case WIDEN_PLUS_EXPR:
+    case WIDEN_MINUS_EXPR:
       if (SCALAR_INT_MODE_P (GET_MODE (op0))
 	  && SCALAR_INT_MODE_P (mode))
 	{
@@ -5404,6 +5410,10 @@ expand_debug_expr (tree exp)
 	    op1 = simplify_gen_unary (ZERO_EXTEND, mode, op1, inner_mode);
 	  else
 	    op1 = simplify_gen_unary (SIGN_EXTEND, mode, op1, inner_mode);
+	  if (TREE_CODE (exp) == WIDEN_PLUS_EXPR)
+	    return simplify_gen_binary (PLUS, mode, op0, op1);
+	  else if (TREE_CODE (exp) == WIDEN_MINUS_EXPR)
+	    return simplify_gen_binary (MINUS, mode, op0, op1);
 	  op0 = simplify_gen_binary (MULT, mode, op0, op1);
 	  if (TREE_CODE (exp) == WIDEN_MULT_EXPR)
 	    return op0;
diff --git a/gcc/testsuite/g++.dg/debug/pr108967.C b/gcc/testsuite/g++.dg/debug/pr108967.C
new file mode 100644
index 00000000000..b50dadc5925
--- /dev/null
+++ b/gcc/testsuite/g++.dg/debug/pr108967.C
@@ -0,0 +1,41 @@
+// PR debug/108967
+// { dg-do compile }
+
+struct F { unsigned short r[8]; };
+extern void foo (F);
+
+static inline F
+bar (F a, F b)
+{
+  for (int i = 0; i < 8; ++i)
+    a.r[i] = a.r[i] + b.r[i] < (unsigned short) -1 ? a.r[i] + b.r[i] : (unsigned short) -1;
+  return a;
+}
+
+static inline void
+baz (F v)
+{
+  foo (v);
+}
+
+void
+qux (F a, F b)
+{
+  F c = bar (a, b);
+  baz (c);
+}
+
+static inline F
+corge (F a, F b)
+{
+  for (int i = 0; i < 8; ++i)
+    a.r[i] = a.r[i] - b.r[i] > 0 ? a.r[i] - b.r[i] : 0;
+  return a;
+}
+
+void
+garply (F a, F b)
+{
+  F c = corge (a, b);
+  baz (c);
+}

                 reply	other threads:[~2023-05-02 20:15 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=20230502201510.C23E438A9087@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).