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.
Loading
Please register or sign in to comment