[Bug tree-optimization/63641] Invalid shift leads to incorrect code on 32-bit system

2014-10-24 Thread ian at airs dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63641

Ian Lance Taylor ian at airs dot com changed:

   What|Removed |Added

 CC||jakub at redhat dot com

--- Comment #1 from Ian Lance Taylor ian at airs dot com ---
I'm guessing that this change is the cause of the problem:

2014-10-17  Jakub Jelinek  ja...@redhat.com

PR tree-optimization/63464
* gimple.h (gimple_seq_discard): New prototype.
* gimple.c: Include stringpool.h and tree-ssanames.h.
(gimple_seq_discard): New function.
* optabs.h (lshift_cheap_p): New prototype.
* optabs.c (lshift_cheap_p): New function, moved from...
* tree-switch-conversion.c (lshift_cheap_p): ... here.
* tree-ssa-reassoc.c: Include gimplify.h and optabs.h.
(reassoc_branch_fixups): New variable.
(update_range_test): Add otherrangep and seq arguments.
Unshare exp.  If otherrange is NULL, use for other ranges
array of pointers pointed by otherrangep instead.
Emit seq before gimplified statements for tem.
(optimize_range_tests_diff): Adjust update_range_test
caller.
(optimize_range_tests_xor): Likewise.  Fix up comment.
(extract_bit_test_mask, optimize_range_tests_to_bit_test): New
functions.
(optimize_range_tests): Adjust update_range_test caller.
Call optimize_range_tests_to_bit_test.
(branch_fixup): New function.
(execute_reassoc): Call branch_fixup.


[Bug tree-optimization/63641] Invalid shift leads to incorrect code on 32-bit system

2014-10-24 Thread ian at airs dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63641

--- Comment #2 from Ian Lance Taylor ian at airs dot com ---
Created attachment 33805
  -- https://gcc.gnu.org/bugzilla/attachment.cgi?id=33805action=edit
sample patch

This patch seems to fix the problem, and the new tests still pass.  But I
haven't done full testing and I'm not entirely sure whether this is the right
approach.


[Bug tree-optimization/63641] Invalid shift leads to incorrect code on 32-bit system

2014-10-24 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63641

Jakub Jelinek jakub at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2014-10-24
 CC||jakub at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #3 from Jakub Jelinek jakub at gcc dot gnu.org ---
I'd say the right fix would be instead:
--- gcc/tree-ssa-reassoc.c2014-10-17 12:53:59.286321210 +0200
+++ gcc/tree-ssa-reassoc.c2014-10-24 22:38:55.762859480 +0200
@@ -2513,7 +2513,7 @@ optimize_range_tests_to_bit_test (enum t
 {
   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)
there is no need to build further trees, and the other use of high also wants
the one smaller value.
The thing is, bit 0 of mask is value lowi, if e.g. wi::clz(mask) is 0, then
it means the topmost bit of mask is set, so the highest value in the interval
is
lowi + prec - 1.  If only lowest bit of mask would be set (not possible, at
least 3 ranges of bits need to be there), then wi::clz(mask) would be prec - 1
and we'd want high to be equal to lowi.  Mask is never zero.