From: Pan Li <pan2...@intel.com>

The phiopt2 pass will also try the gimple_simplify for the form 16
of unsigned integer SAT_ADD.  Thus add the testcase to make sure
it will be performed in phiopt2 pass.

The below test suites are passed for this patch:
1. The rv64gcv fully regression tests.
2. The x86 bootstrap tests.
3. The x86 fully regression tests.

gcc/testsuite/ChangeLog:

        * gcc.dg/sat_arith_simplify.h: Add test helper macros.
        * gcc.dg/sat_u_add-simplify-16-u16.c: New test.
        * gcc.dg/sat_u_add-simplify-16-u32.c: New test.
        * gcc.dg/sat_u_add-simplify-16-u64.c: New test.
        * gcc.dg/sat_u_add-simplify-16-u8.c: New test.

Signed-off-by: Pan Li <pan2...@intel.com>
---
 gcc/testsuite/gcc.dg/sat_arith_simplify.h        | 10 ++++++++++
 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u16.c | 11 +++++++++++
 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u32.c | 11 +++++++++++
 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u64.c | 11 +++++++++++
 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u8.c  | 11 +++++++++++
 5 files changed, 54 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u16.c
 create mode 100644 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u32.c
 create mode 100644 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u64.c
 create mode 100644 gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u8.c

diff --git a/gcc/testsuite/gcc.dg/sat_arith_simplify.h 
b/gcc/testsuite/gcc.dg/sat_arith_simplify.h
index d8e2fee80ad..1ca17151f0c 100644
--- a/gcc/testsuite/gcc.dg/sat_arith_simplify.h
+++ b/gcc/testsuite/gcc.dg/sat_arith_simplify.h
@@ -119,4 +119,14 @@ T sat_u_add_##T##_15 (T x, T y)                 \
     return ret;                                 \
 }
 
+#define DEF_SAT_U_ADD_16(T)                \
+T sat_u_add_##T##_16 (T x, T y)            \
+{                                          \
+  T ret;                                   \
+  if (__builtin_add_overflow (x, y, &ret)) \
+    return -1;                             \
+  else                                     \
+    return ret;                            \
+}
+
 #endif
diff --git a/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u16.c 
b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u16.c
new file mode 100644
index 00000000000..3c6f7347bcc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u16.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_16 (uint16_t)
+
+/* { dg-final { scan-tree-dump-not " if " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " else " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " goto " "phiopt2" } } */
diff --git a/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u32.c 
b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u32.c
new file mode 100644
index 00000000000..8d2f45e59d9
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u32.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_16 (uint32_t)
+
+/* { dg-final { scan-tree-dump-not " if " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " else " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " goto " "phiopt2" } } */
diff --git a/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u64.c 
b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u64.c
new file mode 100644
index 00000000000..7a5de4e6500
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u64.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_16 (uint64_t)
+
+/* { dg-final { scan-tree-dump-not " if " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " else " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " goto " "phiopt2" } } */
diff --git a/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u8.c 
b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u8.c
new file mode 100644
index 00000000000..aa032578279
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/sat_u_add-simplify-16-u8.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt2-details" } */
+
+#include <stdint.h>
+#include "sat_arith_simplify.h"
+
+DEF_SAT_U_ADD_16 (uint8_t)
+
+/* { dg-final { scan-tree-dump-not " if " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " else " "phiopt2" } } */
+/* { dg-final { scan-tree-dump-not " goto " "phiopt2" } } */
-- 
2.43.0

Reply via email to