public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 3/4] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative
@ 2021-11-10 12:49 Richard Sandiford
  2021-11-10 12:56 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Sandiford @ 2021-11-10 12:49 UTC (permalink / raw)
  To: gcc-patches

Mark IFN_UBSAN_CHECK_ADD/MUL as commutative.

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

Richard


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.
---
 gcc/internal-fn.c                          |  2 ++
 gcc/testsuite/gcc.dg/ubsan/commutative-1.c | 30 ++++++++++++++++++++++
 2 files changed, 32 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/ubsan/commutative-1.c

diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index ff7d43f1801..b64555ada36 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -3830,6 +3830,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" } } */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 3/4] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative
  2021-11-10 12:49 [PATCH 3/4] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative Richard Sandiford
@ 2021-11-10 12:56 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2021-11-10 12:56 UTC (permalink / raw)
  To: gcc-patches, richard.sandiford

On Wed, Nov 10, 2021 at 12:49:36PM +0000, Richard Sandiford via Gcc-patches wrote:
> 	* 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.

Ok.

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-11-10 12:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 12:49 [PATCH 3/4] Mark IFN_UBSAN_CHECK_ADD/MUL as commutative Richard Sandiford
2021-11-10 12:56 ` Jakub Jelinek

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