(if (INTEGRAL_TYPE_P (type))
(bit_and @0 @1)))
+/* Fold `(a ? b : 0) | (a ? 0 : c)` into (a ? b : c).
+ Handle also ^ and + in replacement of `|`. */
+(for cnd (cond vec_cond)
+ (for op (bit_ior bit_xor plus)
+ (simplify
+ (op:c
+ (cnd:s @0 @00 integer_zerop)
+ (cnd:s @0 integer_zerop @01))
+ (cnd @0 @00 @01))))
+
(for cmp (tcc_comparison)
icmp (inverted_tcc_comparison)
/* Fold (((a < b) & c) | ((a >= b) & d)) into (a < b ? c : d) & 1. */
--- /dev/null
+/* PR tree-optimization/103660 */
+/* Vector type version. */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop2-raw -Wno-psabi" } */
+
+typedef int v4si __attribute((__vector_size__(4 * sizeof(int))));
+#define funcs(OP,n) \
+v4si min_##n(v4si a, v4si b) { \
+ v4si t = {0,0,0,0}; \
+ v4si X = a < b ? a : t; \
+ v4si Y = a < b ? t : b; \
+ return (X OP Y); \
+} \
+v4si f_##n(v4si a, v4si b, \
+ v4si c, v4si d) { \
+ v4si t = {0,0,0,0}; \
+ v4si X = a < b ? c : t; \
+ v4si Y = a < b ? t : d; \
+ return (X OP Y); \
+}
+
+
+funcs(|, ior)
+funcs(^, xor)
+funcs(+, plus)
+
+/* min_ior/min_xor/min_plus 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/f_xor/f_plus should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr, " "forwprop2" } } */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop2" } } */
+/* { dg-final { scan-tree-dump-not "plus_expr, " "forwprop2" } } */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop2" } } */
+/* { dg-final { scan-tree-dump-times "(?:lt_expr|min_expr), " 6 "forwprop2" } } */
+/* { dg-final { scan-tree-dump-times "(?:vec_cond_expr|min_expr), " 6 "forwprop2" } } */
--- /dev/null
+/* PR tree-optimization/103660 */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fgimple -fdump-tree-forwprop1-raw" } */
+
+#define funcs(OP,n) \
+__GIMPLE() \
+int min_##n(int a, int b) { \
+ _Bool X; \
+ int t; \
+ int t1; \
+ int t2; \
+ X = a < b; \
+ t1 = X ? a : 0; \
+ t2 = X ? 0 : b; \
+ t = t1 OP t2; \
+ return t; \
+} \
+__GIMPLE() \
+int f_##n(int a, int b, int c, \
+ int d) { \
+ _Bool X; \
+ int t; \
+ int t1; \
+ int t2; \
+ X = a < b; \
+ t1 = X ? c : 0; \
+ t2 = X ? 0 : d; \
+ t = t1 OP t2; \
+ return t; \
+}
+
+funcs(|, ior)
+funcs(^, xor)
+funcs(+, plus)
+
+/* min_i/min_ioror/min_plus should produce min<a,b> */
+/* f_xor/f_ior/f_plus should produce (a < b) ? c : d */
+/* { dg-final { scan-tree-dump-not "bit_xor_expr, " "forwprop1" } } */
+/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "forwprop1" } } */
+/* { dg-final { scan-tree-dump-not "plus_expr, " "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "min_expr, " 3 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "lt_expr, " 3 "forwprop1" } } */
+/* { dg-final { scan-tree-dump-times "cond_expr, " 3 "forwprop1" } } */