(absu tree_expr_nonnegative_p@0)
(convert @0))
-/* Simplify (-(X < 0) | 1) * X into abs (X). */
+/* Simplify (-(X < 0) | 1) * X into abs (X) or absu(X). */
(simplify
- (mult:c (bit_ior (negate (convert? (lt @0 integer_zerop))) integer_onep) @0)
- (if (INTEGRAL_TYPE_P (type) && !TYPE_UNSIGNED (type))
- (abs @0)))
-
-/* Similarly (-(X < 0) | 1U) * X into absu (X). */
-(simplify
- (mult:c (bit_ior (nop_convert (negate (convert? (lt @0 integer_zerop))))
- integer_onep) (nop_convert @0))
+ (mult:c (nop_convert1?
+ (bit_ior (nop_convert2? (negate (convert? (lt @0 integer_zerop))))
+ integer_onep))
+ (nop_convert3? @0))
(if (INTEGRAL_TYPE_P (type)
- && TYPE_UNSIGNED (type)
&& INTEGRAL_TYPE_P (TREE_TYPE (@0))
&& !TYPE_UNSIGNED (TREE_TYPE (@0)))
- (absu @0)))
+ (if (TYPE_UNSIGNED (type))
+ (absu @0)
+ (abs @0)
+ )
+ )
+)
/* A few cases of fold-const.c negate_expr_p predicate. */
(match negate_expr_p
--- /dev/null
+/* PR tree-optimization/103245 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-times " = ABSU_EXPR <v_\[0-9]*\\\(D\\\)>;" 1 "optimized" } } */
+
+unsigned
+f1 (int v)
+{
+ unsigned int d_6;
+ int b_5;
+ int a_4;
+ _Bool _1;
+ unsigned int v1_2;
+ unsigned int _7;
+ int _9;
+
+ _1 = v < 0;
+ a_4 = (int) _1;
+ b_5 = -a_4;
+ _9 = b_5 | 1;
+ d_6 = (unsigned int) _9;
+ v1_2 = (unsigned int) v;
+ _7 = v1_2 * d_6;
+ return _7;
+}