Skip to content
Snippets Groups Projects
Commit ec8e8d35 authored by Richard Sandiford's avatar Richard Sandiford
Browse files

Try to simplify (X >> C1) << (C1 + C2) -> X << C2

This patch adds a rule to simplify (X >> C1) << (C1 + C2) -> X << C2
when the low C1 bits of X are known to be zero.

Any single conversion can take place between the shifts.  E.g. for
a truncating conversion, any extra bits of X that are preserved by
truncating after the shift are immediately lost by the shift left.
And the sign bits used for an extending conversion are the same as
the sign bits used for the rshift.  (A double conversion of say
int->unsigned->uint64_t would be wrong though.)

gcc/
	* match.pd: Simplify (X >> C1) << (C1 + C2) -> X << C2 if the
	low C1 bits of X are zero.

gcc/testsuite/
	* gcc.dg/tree-ssa/shifts-1.c: New test.
	* gcc.dg/tree-ssa/shifts-2.c: Likewise.
parent 8d01bc7d
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment