public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5605] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative
@ 2021-11-30  9:53 Richard Sandiford
  0 siblings, 0 replies; only message in thread
From: Richard Sandiford @ 2021-11-30  9:53 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:12e38012786d18b21ecb85c5d13b532281206270

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

    Mark IFN_UBSAN_CHECK_ADD/MUL as commutative
    
    gcc/
            * internal-fn.c (commutative_binary_fn_p): Handle IFN_UBSAN_CHECK_ADD
            and IFN_UBSAN_CHECK_MUL.
    
    gcc/testsuite/
            * gcc.dg/ubsan/commutative-1.c: New test.

Diff:
---
 gcc/internal-fn.c                          |  2 ++
 gcc/testsuite/gcc.dg/ubsan/commutative-1.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 3d4055d29ee..0e377b1b1f8 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3832,6 +3832,8 @@ commutative_binary_fn_p (internal_fn fn)
     case IFN_FMIN:
     case IFN_FMAX:
     case IFN_COMPLEX_MUL:
+    case IFN_UBSAN_CHECK_ADD:
+    case IFN_UBSAN_CHECK_MUL:
       return true;
 
     default:
diff --git a/gcc/testsuite/gcc.dg/ubsan/commutative-1.c b/gcc/testsuite/gcc.dg/ubsan/commutative-1.c
new file mode 100644
index 00000000000..128f5b14697
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ubsan/commutative-1.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined -fdump-tree-optimized" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-flto" } { "" } } */
+
+int res[2];
+
+void
+f1 (int x, int y)
+{
+  res[0] = x + y;
+  res[1] = y + x;
+}
+
+void
+f2 (int x, int y)
+{
+  res[0] = x - y;
+  res[1] = y - x;
+}
+
+void
+f3 (int x, int y)
+{
+  res[0] = x * y;
+  res[1] = y * x;
+}
+
+/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_ADD} 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_SUB} 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times {\.UBSAN_CHECK_MUL} 1 "optimized" } } */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-11-30  9:53 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30  9:53 [gcc r12-5605] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative Richard Sandiford

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).