IOR part of the bug report was fixed by
r13-4620-g4d9db4bdd458 but
that added only aarch64 specific testcases. This adds 4
generic testcases for this to check to make sure they are optimized.
The C++ testcases are the vector type versions.
PR tree-optimization/103660
gcc/testsuite/ChangeLog:
* g++.dg/tree-ssa/pr103660-0.C: New test.
* g++.dg/tree-ssa/pr103660-1.C: New test.
* gcc.dg/tree-ssa/pr103660-0.c: New test.
* gcc.dg/tree-ssa/pr103660-1.c: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
--- /dev/null
+/* PR tree-optimization/103660 */
+/* Vector type version. */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1-raw -Wno-psabi" } */
+
+typedef int v4si __attribute((__vector_size__(4 * sizeof(int))));
+#define funcs(OP,n) \
+v4si min_##n(v4si a, v4si b) { \
+ v4si X = -(a < b) * a; \
+ v4si Y = -(a >= b) * b; \
+ return (X OP Y); \
+} \
+v4si f_##n(v4si a, v4si b, \
+ v4si c, v4si d) { \
+ v4si X = -(a < b) * c; \
+ v4si Y = -(a >= b) * d; \
+ return (X OP Y); \
+}
+
+
+funcs(|, ior)
+
+/* min_ior should produce min<a,b> or `a < b ? a : b` depending on if the target
+ supports min on the vector type or not. */
+/* f_ior should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "(?:lt_expr|min_expr), " 2 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "(?:vec_cond_expr|min_expr), " 2 "forwprop1" } } */
--- /dev/null
+/* PR tree-optimization/103660 */
+/* Vector type version. */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop1-raw -Wno-psabi" } */
+
+typedef int v4si __attribute((__vector_size__(4 * sizeof(int))));
+#define funcs(OP,n) \
+v4si min_##n(v4si a, v4si b) { \
+ v4si X = a < b ? a : 0; \
+ v4si Y = a >= b ? b : 0; \
+ return (X OP Y); \
+} \
+v4si f_##n(v4si a, v4si b, \
+ v4si c, v4si d) { \
+ v4si X = a < b ? c : 0; \
+ v4si Y = a >= b ? d : 0; \
+ return (X OP Y); \
+}
+
+
+funcs(|, ior)
+
+/* min_ior should produce min<a,b> or `a < b ? a : b` depending on if the target
+ supports min on the vector type or not. */
+/* f_ior should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "(?:lt_expr|min_expr), " 2 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "(?:vec_cond_expr|min_expr), " 2 "forwprop1" } } */
--- /dev/null
+/* PR tree-optimization/103660 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop4-raw" } */
+
+#define funcs(OP,n) \
+int min_##n(int a, int b) { \
+ int t; \
+ int t1; \
+ int t2; \
+ t1 = (a < b) * a; \
+ t2 = (a >= b) * b; \
+ t = t1 OP t2; \
+ return t; \
+} \
+int f_##n(int a, int b, int c, \
+ int d) { \
+ int t; \
+ int t1; \
+ int t2; \
+ t1 = (a < b) * c; \
+ t2 = (a >= b) * d; \
+ t = t1 OP t2; \
+ return t; \
+}
+
+funcs(|, ior)
+
+/* min_ior should produce min<a,b> */
+/* f_ior should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "min_expr, " 1 "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "lt_expr, " 1 "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "cond_expr, " 1 "forwprop4" } } */
--- /dev/null
+/* PR tree-optimization/103660 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fgimple -fdump-tree-forwprop4-raw" } */
+
+#define funcs(OP,n) \
+__GIMPLE() \
+int min_##n(int a, int b) { \
+ _Bool X; \
+ _Bool Y; \
+ int t; \
+ int t1; \
+ int t2; \
+ X = a < b; \
+ Y = a >= b; \
+ t1 = X ? a : 0; \
+ t2 = Y ? b : 0; \
+ t = t1 OP t2; \
+ return t; \
+} \
+__GIMPLE() \
+int f_##n(int a, int b, int c, \
+ int d) { \
+ _Bool X; \
+ _Bool Y; \
+ int t; \
+ int t1; \
+ int t2; \
+ X = a < b; \
+ Y = a >= b; \
+ t1 = X ? c : 0; \
+ t2 = Y ? d : 0; \
+ t = t1 OP t2; \
+ return t; \
+}
+
+funcs(|, ior)
+
+/* min_ior should produce min<a,b> */
+/* f_ior should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "min_expr, " 1 "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "lt_expr, " 1 "forwprop4" } } */
+/* { dg-final { scan-tree-dump-times "cond_expr, " 1 "forwprop4" } } */