On 08/03/2016 09:29 AM, David Malcolm wrote:
On Wed, 2016-08-03 at 15:47 +0200, Richard Biener wrote:
On Wed, Aug 3, 2016 at 6:00 AM, Patrick Palka <patr...@parcs.ath.cx>
wrote:
VRP currently has functionality to eliminate case labels that lie
completely outside of the switch operand's value range.  This patch
complements this functionality by teaching VRP to also truncate the
case
label ranges that partially overlap with the operand's value range.

Bootstrapped and regtested on x86_64-pc-linux-gnu.  Does this look
like
a reasonable optimization?  Admittedly, its effect will almost
always be
negligible except in cases where a case label range spans a large
number
of values which is a pretty rare thing.  The optimization triggered
about 250 times during bootstrap.

I think it's most useful when the range collapses to a single value.

Ok.

Is this always an improvement?   I can see that it can simplify things,
eliminate dead code etc, but could it make evaluating the switch less
efficient?
I don't think so. We should recognize that the default fall-thru doesn't happen because of the range associated with CH as we enter the switch.

So, in theory we'd still be able to collapse down to

if (ch > 17)
  return
if (ch == 0)
  foo ();
else
  bar ();

I haven't actually checked though.


Jeff

Reply via email to