[PATCH] Compile (X & C) == 0 to (X >> C) & 1 == 0 only at RTL level
Paolo Bonzini
bonzini@gnu.org
Fri Aug 29 09:38:00 GMT 2008
This patch mostly reverts this patch from Jeff Law:
2003-07-02 Jeff Law <law@redhat.com>
* expr.c (do_store_flag): Remove special case folding for
single bit tests. Instead call back into the commonized folder
routine.
* fold-const.c (fold_single_bit_test): New function, mostly
extracted from do_store_flag, with an additional case extracted
from fold.
(fold): Call fold_single_bit_test appropriately.
* tree.h (fold_single_bit_test): Prototype.
The reason is that nowadays the canonical form of single-bit tests is
back to being (X & C) == 0, and under bad conditions that canonical form
will be reestablished within fold_single_bit_test after carefully
crafting a (X >> C) & 1 expression. This causes an infinite loop
because do_store_flag is called again to expand (X & C) == 0.
In my case, the problem is that I added a NOP_EXPR folding. Then the
last fold_convert in fold_single_bit_test rebuilds the BIT_AND_EXPR for
(X >> C) & 1 and, fold_binary causes the canonicalization to happen. At
least this means that my NOP_EXPR folding is very effective in making
canonical forms. :-)
I decided to revert (almost) Jeff's patch because fold-const.c is *not*
anymore calling fold_single_bit_test; only expr.c is. Instead,
fold_single_bit_test_into_sign_test is being called from fold-const.c,
and that path is left in place.
Bootstrapped i686-pc-linux-gnu, regtest in progress. Ok?
Paolo
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fold-recursion.patch
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080829/a39f5b90/attachment.ksh>
More information about the Gcc-patches
mailing list