From 46a547083ac283bfea3406980a58f1f17b90c5c3 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Sat, 25 Oct 2014 22:21:47 +0200 Subject: [PATCH] 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 --- gcc/ChangeLog | 6 +++ gcc/testsuite/ChangeLog | 5 ++ gcc/testsuite/gcc.c-torture/execute/pr63641.c | 54 +++++++++++++++++++ gcc/tree-ssa-reassoc.c | 2 +- 4 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr63641.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a7bcfbfac66..1cb0cdc5569 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2014-10-25 Jakub Jelinek + + 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 PR rtl-optimization/63615 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 00a78cc1118..788786c068e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2014-10-25 Jakub Jelinek + + PR tree-optimization/63641 + * gcc.c-torture/execute/pr63641.c: New test. + 2014-10-24 Tobias Burnus * 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 00000000000..d08c50b4f14 --- /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 159f217bbe4..a760595a1fd 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) -- 2.30.2