2020-05-08 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/94783
+ * match.pd ((X + (X >> (prec - 1))) ^ (X >> (prec - 1)) to abs (X)):
+ New simplification.
+
PR tree-optimization/94956
* match.pd (FFS): Optimize __builtin_ffs* of non-zero argument into
__builtin_ctz* + 1 if direct IFN_CTZ is supported.
(with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
(convert (absu:utype @0)))))
+#if GIMPLE
+/* Optimize (X + (X >> (prec - 1))) ^ (X >> (prec - 1)) into abs (X). */
+(simplify
+ (bit_xor:c (plus:c @0 (rshift@2 @0 INTEGER_CST@1)) @2)
+ (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && !TYPE_UNSIGNED (TREE_TYPE (@0))
+ && wi::to_widest (@1) == element_precision (TREE_TYPE (@0)) - 1)
+ (abs @0)))
+#endif
/* Simplifications of operations with one constant operand and
simplifications to constants or single values. */
2020-05-08 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/94783
+ * gcc.dg/tree-ssa/pr94783.c: New test.
+
PR tree-optimization/94956
* gcc.target/i386/pr94956.c: New test.
--- /dev/null
+/* PR tree-optimization/94783 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump "ABS_EXPR" "optimized" } } */
+/* { dg-final { scan-tree-dump-not " >> 31" "optimized" } } */
+
+int
+foo (int v)
+{
+ int mask = v >> (__SIZEOF_INT__ * __CHAR_BIT__ - 1);
+ return (v + mask) ^ mask;
+}