Here is the second patch in the series. Its purpose is to extend the current bswap optimization to handle bitwise operations on memory sources (array and structures). This patch extends the concept of symbolic number used in the bswap pass to memorize some extra informations for bitwise operations on memory source: base of the access (beginning of the array or structure), offset to the base and size of the access. All the logic to work on memory source is in how to merge two symbolic numbers into one according to the offsets of the two initial symbolic number and the target endianness: the symbolic number with bigger offset would see its values incremented on a little endian machine.
Note that as it stands the patch does not work for arrays indexed with variable (such a tab[a] || (tab[a+1] << 8)) because fold_const does not fold (a + 1) - a. If it was found that some software uses that, adding a new folding would make this code cover more cases. This patch also adds a few testcases to check both (i) that the optimization works as expected and (ii) that the result are correct. The ChangeLog are as follows: *** gcc/ChangeLog *** 2014-04-01 Thomas Preud'homme <thomas.preudho...@arm.com> PR tree-optimization/54733 * tree-ssa-math-opts.c (find_bswap_1): Add support for memory source. (find_bswap): Likewise. (execute_optimize_bswap): Likewise. *** gcc/testsuite/ChangeLog *** 2014-04-01 Thomas Preud'homme <thomas.preudho...@arm.com> PR tree-optimization/54733 * gcc.dg/optimize-bswapdi-3.c: New test to check extension of bswap optimization to support memory sources. * gcc.dg/optimize-bswaphi-1.c: Likewise. * gcc.dg/optimize-bswapsi-2.c: Likewise. * gcc.c-torture/execute/bswap-2.c: Likewise. Is this ok for stage 1? Best regards, Thomas
gcc32rm-84.3.part2.diff
Description: Binary data