aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2014-10-25 22:21:47 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2014-10-25 22:21:47 +0200
commit46a547083ac283bfea3406980a58f1f17b90c5c3 (patch)
treebe8c1c5907e40185f6fcf7140f52f1d62ac08896 /gcc
parent608b9c889efe2b27282ced89114d07e7e9b013ad (diff)
downloadgcc-46a547083ac283bfea3406980a58f1f17b90c5c3.zip
gcc-46a547083ac283bfea3406980a58f1f17b90c5c3.tar.gz
gcc-46a547083ac283bfea3406980a58f1f17b90c5c3.tar.bz2
re PR tree-optimization/63641 (Invalid shift leads to incorrect code on 32-bit system)
PR tree-optimization/63641 * tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Set high to low + prec - 1 - clz (mask) instead of low + prec - clz (mask). * gcc.c-torture/execute/pr63641.c: New test. From-SVN: r216693
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr63641.c54
-rw-r--r--gcc/tree-ssa-reassoc.c2
4 files changed, 66 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a7bcfbf..1cb0cdc 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2014-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/63641
+ * tree-ssa-reassoc.c (optimize_range_tests_to_bit_test): Set high
+ to low + prec - 1 - clz (mask) instead of low + prec - clz (mask).
+
2014-10-25 Alan Modra <amodra@gmail.com>
PR rtl-optimization/63615
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 00a78cc..788786c 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-10-25 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/63641
+ * gcc.c-torture/execute/pr63641.c: New test.
+
2014-10-24 Tobias Burnus <burnus@net-b.de>
* gfortran.dg/coarray_collectives_9.f90: Remove dg-error.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr63641.c b/gcc/testsuite/gcc.c-torture/execute/pr63641.c
new file mode 100644
index 0000000..d08c50b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr63641.c
@@ -0,0 +1,54 @@
+/* PR tree-optimization/63641 */
+
+__attribute__ ((noinline, noclone)) int
+foo (unsigned char b)
+{
+ if (0x0 <= b && b <= 0x8)
+ goto lab;
+ if (b == 0x0b)
+ goto lab;
+ if (0x0e <= b && b <= 0x1a)
+ goto lab;
+ if (0x1c <= b && b <= 0x1f)
+ goto lab;
+ return 0;
+lab:
+ return 1;
+}
+
+__attribute__ ((noinline, noclone)) int
+bar (unsigned char b)
+{
+ if (0x0 <= b && b <= 0x8)
+ goto lab;
+ if (b == 0x0b)
+ goto lab;
+ if (0x0e <= b && b <= 0x1a)
+ goto lab;
+ if (0x3c <= b && b <= 0x3f)
+ goto lab;
+ return 0;
+lab:
+ return 1;
+}
+
+char tab1[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1 };
+char tab2[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1 };
+
+int
+main ()
+{
+ int i;
+ asm volatile ("" : : : "memory");
+ for (i = 0; i < 256; i++)
+ if (foo (i) != (i < 32 ? tab1[i] : 0))
+ __builtin_abort ();
+ for (i = 0; i < 256; i++)
+ if (bar (i) != (i < 64 ? tab2[i] : 0))
+ __builtin_abort ();
+ return 0;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 159f217..a760595 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -2513,7 +2513,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
{
tree high = wide_int_to_tree (TREE_TYPE (lowi),
wi::to_widest (lowi)
- + prec - wi::clz (mask));
+ + prec - 1 - wi::clz (mask));
operand_entry_t oe = (*ops)[ranges[i].idx];
tree op = oe->op;
gimple stmt = op ? SSA_NAME_DEF_STMT (op)