aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2020-01-07 11:03:07 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2020-01-07 11:03:07 +0100
commitf26916c2acdda19e36e57fff97b296897ebcba76 (patch)
treedf16e28845517b34758987ce1960774bccac998b /gcc
parent5c4177c5087194f920413896b1a382f807c1d0f2 (diff)
downloadgcc-f26916c2acdda19e36e57fff97b296897ebcba76.zip
gcc-f26916c2acdda19e36e57fff97b296897ebcba76.tar.gz
gcc-f26916c2acdda19e36e57fff97b296897ebcba76.tar.bz2
re PR tree-optimization/93118 (>>32<<32 is not always converted into &~0ffffffffull at the tree level)
PR tree-optimization/93118 * match.pd ((x >> c) << c -> x & (-1<<c)): Add nop_convert?. Add new simplifier with two intermediate conversions. * gcc.dg/tree-ssa/pr93118.c: New test. From-SVN: r279950
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/match.pd21
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr93118.c45
4 files changed, 75 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 568076b..f90dc08 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-01-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/93118
+ * match.pd ((x >> c) << c -> x & (-1<<c)): Add nop_convert?. Add new
+ simplifier with two intermediate conversions.
+
2020-01-07 Martin Liska <mliska@suse.cz>
* params.opt: Add Optimization for various parameters.
diff --git a/gcc/match.pd b/gcc/match.pd
index fac1dfc..a3badb2 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2738,9 +2738,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Optimize (x >> c) << c into x & (-1<<c). */
(simplify
- (lshift (rshift @0 INTEGER_CST@1) @1)
+ (lshift (nop_convert? (rshift @0 INTEGER_CST@1)) @1)
(if (wi::ltu_p (wi::to_wide (@1), element_precision (type)))
- (bit_and @0 (lshift { build_minus_one_cst (type); } @1))))
+ /* It doesn't matter if the right shift is arithmetic or logical. */
+ (bit_and (view_convert @0) (lshift { build_minus_one_cst (type); } @1))))
+
+(simplify
+ (lshift (convert (convert@2 (rshift @0 INTEGER_CST@1))) @1)
+ (if (wi::ltu_p (wi::to_wide (@1), element_precision (type))
+ /* Allow intermediate conversion to integral type with whatever sign, as
+ long as the low TYPE_PRECISION (type)
+ - TYPE_PRECISION (TREE_TYPE (@2)) bits are preserved. */
+ && INTEGRAL_TYPE_P (type)
+ && INTEGRAL_TYPE_P (TREE_TYPE (@2))
+ && INTEGRAL_TYPE_P (TREE_TYPE (@0))
+ && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0))
+ && (TYPE_PRECISION (TREE_TYPE (@2)) >= TYPE_PRECISION (type)
+ || wi::geu_p (wi::to_wide (@1),
+ TYPE_PRECISION (type)
+ - TYPE_PRECISION (TREE_TYPE (@2)))))
+ (bit_and (convert @0) (lshift { build_minus_one_cst (type); } @1))))
/* Optimize (x << c) >> c into x & ((unsigned)-1 >> c) for unsigned
types. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 4e02fb4..403bc8a 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/93118
+ * gcc.dg/tree-ssa/pr93118.c: New test.
+
2020-01-07 Martin Liska <mliska@suse.cz>
PR tree-optimization/92860
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr93118.c b/gcc/testsuite/gcc.dg/tree-ssa/pr93118.c
new file mode 100644
index 0000000..92e9310
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr93118.c
@@ -0,0 +1,45 @@
+/* PR tree-optimization/93118 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+/* { dg-final { scan-tree-dump-not ">>" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "<<" "optimized" } } */
+
+#if __SIZEOF_LONG_LONG__ == 8 && __SIZEOF_INT__ == 4 && __CHAR_BIT__ == 8
+unsigned long long
+foo (unsigned long long a)
+{
+ unsigned long long b = a >> 32;
+ int c = b;
+ unsigned long long d = c;
+ return d << 32;
+}
+
+unsigned long long
+bar (unsigned long long a)
+{
+ unsigned long long b = a >> 32;
+ unsigned c = b;
+ unsigned long long d = c;
+ return d << 32;
+}
+
+unsigned long long
+baz (long long a)
+{
+ long long b = a >> 32;
+ unsigned long long c = b;
+ return c << 32;
+}
+
+typedef unsigned V __attribute__((vector_size (2 * sizeof (int))));
+typedef int W __attribute__((vector_size (2 * sizeof (int))));
+
+void
+quux (W *w, V *v)
+{
+ W a = (W) (*v >> 16);
+ *w = a << 16;
+}
+#else
+int i;
+#endif