{ tree utype = unsigned_type_for (type); }
(convert (rshift (lshift (convert:utype @0) @2) @3))))))
+/* Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit. */
+(simplify
+ (lshift (convert (lt @0 integer_zerop@1)) INTEGER_CST@2)
+ (if (TYPE_SIGN (TREE_TYPE (@0)) == SIGNED
+ && wi::eq_p (wi::to_wide (@2), TYPE_PRECISION (TREE_TYPE (@0)) - 1))
+ (with { wide_int wone = wi::one (TYPE_PRECISION (type)); }
+ (bit_and (convert @0)
+ { wide_int_to_tree (type,
+ wi::lshift (wone, wi::to_wide (@2))); }))))
+
/* Fold (-x >> C) into -(x > 0) where C = precision(type) - 1. */
(for cst (INTEGER_CST VECTOR_CST)
(simplify
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* PR tree-optimization/103218 */
+
+/* These first two are removed during forwprop1 */
+signed char f(signed char a)
+{
+ signed char t = a < 0;
+ int tt = (unsigned char)(t << 7);
+ return tt;
+}
+signed char f0(signed char a)
+{
+ unsigned char t = a < 0;
+ int tt = (unsigned char)(t << 7);
+ return tt;
+}
+
+/* This one is removed during phiopt. */
+signed char f1(signed char a)
+{
+ if (a < 0)
+ return 1u<<7;
+ return 0;
+}
+
+/* These three examples should remove "a < 0" by optimized. */
+/* { dg-final { scan-tree-dump-times "< 0" 0 "optimized"} } */