aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2021-11-30 09:52:27 +0000
committerRichard Sandiford <richard.sandiford@arm.com>2021-11-30 09:52:27 +0000
commitb1d15146b636120f49fbecdb65302ac8d3b48e8b (patch)
treea74ed9f315a108784794fc9323500c200b86b03d
parent12e38012786d18b21ecb85c5d13b532281206270 (diff)
downloadgcc-b1d15146b636120f49fbecdb65302ac8d3b48e8b.zip
gcc-b1d15146b636120f49fbecdb65302ac8d3b48e8b.tar.gz
gcc-b1d15146b636120f49fbecdb65302ac8d3b48e8b.tar.bz2
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.
-rw-r--r--gcc/internal-fn.c2
-rw-r--r--gcc/testsuite/gcc.dg/add-mul-overflow-1.c28
2 files changed, 30 insertions, 0 deletions
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 0e377b1..6ac3460 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 0000000..b23cddd
--- /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" } } */