public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Sandiford <rsandifo@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r12-5606] Mark IFN_ADD/MUL_OVERFLOW as commutative
Date: Tue, 30 Nov 2021 09:53:31 +0000 (GMT)	[thread overview]
Message-ID: <20211130095331.ACF75385803D@sourceware.org> (raw)

https://gcc.gnu.org/g:b1d15146b636120f49fbecdb65302ac8d3b48e8b

commit r12-5606-gb1d15146b636120f49fbecdb65302ac8d3b48e8b
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue Nov 30 09:52:27 2021 +0000

    Mark IFN_ADD/MUL_OVERFLOW as commutative
    
    gcc/
            * internal-fn.c (commutative_binary_fn_p): Handle IFN_ADD_OVERFLOW
            and IFN_MUL_OVERFLOW.
    
    gcc/testsuite/
            * gcc.dg/add-mul-overflow-1.c: New test.

Diff:
---
 gcc/internal-fn.c                         |  2 ++
 gcc/testsuite/gcc.dg/add-mul-overflow-1.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 0e377b1b1f8..6ac3460d538 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3834,6 +3834,8 @@ commutative_binary_fn_p (internal_fn fn)
     case IFN_COMPLEX_MUL:
     case IFN_UBSAN_CHECK_ADD:
     case IFN_UBSAN_CHECK_MUL:
+    case IFN_ADD_OVERFLOW:
+    case IFN_MUL_OVERFLOW:
       return true;
 
     default:
diff --git a/gcc/testsuite/gcc.dg/add-mul-overflow-1.c b/gcc/testsuite/gcc.dg/add-mul-overflow-1.c
new file mode 100644
index 00000000000..b23cdddbb63
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/add-mul-overflow-1.c
@@ -0,0 +1,28 @@
+/* { dg-options "-O -fdump-tree-optimized" } */
+
+int res[4];
+
+void
+f1 (int x, int y)
+{
+  res[2] = __builtin_add_overflow (x, y, res + 0);
+  res[3] = __builtin_add_overflow (y, x, res + 1);
+}
+
+void
+f2 (int x, int y)
+{
+  res[2] = __builtin_sub_overflow (x, y, res + 0);
+  res[3] = __builtin_sub_overflow (y, x, res + 1);
+}
+
+void
+f3 (int x, int y)
+{
+  res[2] = __builtin_mul_overflow (x, y, res + 0);
+  res[3] = __builtin_mul_overflow (y, x, res + 1);
+}
+
+/* { dg-final { scan-tree-dump-times {\.ADD_OVERFLOW} 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times {\.SUB_OVERFLOW} 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times {\.MUL_OVERFLOW} 1 "optimized" } } */


                 reply	other threads:[~2021-11-30  9:53 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=20211130095331.ACF75385803D@sourceware.org \
    --to=rsandifo@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).