[Bug tree-optimization/89184] GCC does not simplify expressions involving shifts, bitwise operators and comparisons.

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Feb 4 10:36:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89184

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #1)
> So in high level terms (let's not do asm when we don't need to), you want
>   ((i >> 1) & 3) == 2
> replaced with
>   i & (3 << 1) == (2 << 1)
> (as long as (i>>1) and (i>>1)&3 are not used for anything else)
> 
> That makes sense.

But only if the (3 << 1) and (2 << 1) constants aren't more expensive than the
3 and 2 constants.  If e.g. the constants before shifting left fit into signed
13 (or whatever else) immediate that can be in directly used in an instruction,
while the left shifted constant(s) do not, this would not be an optimization.
So, doing it e.g. in match.pd can be done only for expression canonicalization
and we need to be able to undo it on a target by target basis later on.


More information about the Gcc-bugs mailing list