aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
diff options
context:
space:
mode:
authorAndrew Pinski <apinski@marvell.com>2021-11-13 04:16:55 +0000
committerAndrew Pinski <apinski@marvell.com>2021-11-16 15:07:39 +0000
commit11c4a06a6c1a9db0bfdb3ee8509392dd7163709c (patch)
tree80270fb57c185187dd247904448330e62acadb8b /gcc/testsuite
parent8d8e8f3ad567c7bd1de708fcc841f691d9686c4d (diff)
downloadgcc-11c4a06a6c1a9db0bfdb3ee8509392dd7163709c.zip
gcc-11c4a06a6c1a9db0bfdb3ee8509392dd7163709c.tar.gz
gcc-11c4a06a6c1a9db0bfdb3ee8509392dd7163709c.tar.bz2
tree-optimization: [PR103218] Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit
This folds Fold ((type)(a<0)) << SIGNBITOFA into ((type)a) & signbit inside match.pd. This was already handled in fold-cost by: /* A < 0 ? <sign bit of A> : 0 is simply (A & <sign bit of A>). */ I have not removed as we only simplify "a ? POW2 : 0" at the gimple level to "a << CST1" and fold actually does the reverse of folding "(a<0)<<CST" into "(a<0) ? 1<<CST : 0". OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/103218 gcc/ChangeLog: * match.pd: New pattern for "((type)(a<0)) << SIGNBITOFA". gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr103218-1.c: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c
new file mode 100644
index 0000000..f086f07
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr103218-1.c
@@ -0,0 +1,28 @@
+/* { 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"} } */