public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Sandiford <richard.sandiford@arm.com>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH 4/4] Mark IFN_ADD/MUL_OVERFLOW as commutative
Date: Wed, 10 Nov 2021 12:50:09 +0000	[thread overview]
Message-ID: <mpt5yt0uqda.fsf@arm.com> (raw)

Mark IFN_ADD/MUL_OVERFLOW as commutative.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


gcc/
	* internal-fn.c (first_commutative_operand): Handle IFN_ADD_OVERFLOW
	and IFN_MUL_OVERFLOW.

gcc/testsuite/
	* gcc.dg/add-mul-overflow-1.c: New test.
---
 gcc/internal-fn.c                         |  2 ++
 gcc/testsuite/gcc.dg/add-mul-overflow-1.c | 28 +++++++++++++++++++++++
 2 files changed, 30 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/add-mul-overflow-1.c

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index b64555ada36..10f08182f7e 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3867,6 +3867,8 @@ first_commutative_argument (internal_fn fn)
     case IFN_FMS:
     case IFN_FNMA:
     case IFN_FNMS:
+    case IFN_ADD_OVERFLOW:
+    case IFN_MUL_OVERFLOW:
       return 0;
 
     case IFN_COND_ADD:
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" } } */
-- 
2.25.1


             reply	other threads:[~2021-11-10 12:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 12:50 Richard Sandiford [this message]
2021-11-10 12:57 ` Jakub Jelinek

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=mpt5yt0uqda.fsf@arm.com \
    --to=richard.sandiford@arm.com \
    --cc=gcc-patches@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).