On 01/07/2013 01:42 PM, Steven Bosscher wrote:
typedef enum fruits { banana = 0, apple = 1, pear = 2, orange = 3 } fruit;
extern void price_fruit_of_the_day (int);
void
discount_of_the_day (fruit f)
{
int p, c = (int) f;
switch (f)
{
case banana:
UNREACHABLE ();
case apple:
p = 3 * c + 4;
break;
case pear:
case orange:
p = 7;
break;
}
price_fruit_of_the_day (p);
}
So if we look at this (I'll analyze the other cases separately).
In reassoc2 we have:
# BLOCK 2 freq:10000
# PRED: ENTRY [100.0%] (fallthru,exec)
c_3 = (int) f_2(D);
switch (f_2(D)) <default: <L4>, case 0: <L0>, case 1: <L1>, case 2
... 3: <L2>>
# SUCC: 6 [25.0%] (exec) 3 [25.0%] (exec) 4 [25.0%] (exec) 5
[25.0%] (exec)
# BLOCK 3 freq:2500
# PRED: 2 [25.0%] (exec)
<L0>:
# VUSE <.MEM_8(D)>
__builtin_unreachable ();
# SUCC:
# BLOCK 4 freq:2500
# PRED: 2 [25.0%] (exec)
<L1>:
D.1724_5 = c_3 * 3;
p_6 = D.1724_5 + 4;
goto <bb 6> (<L4>);
# SUCC: 6 [100.0%] (fallthru,exec)
# BLOCK 5 freq:2500
# PRED: 2 [25.0%] (exec)
<L2>:
# SUCC: 6 [100.0%] (fallthru,exec)
# BLOCK 6 freq:7500
# PRED: 2 [25.0%] (exec) 4 [100.0%] (fallthru,exec) 5 [100.0%]
(fallthru,exec)
# p_1 = PHI <p_4(D)(2), p_6(4), 7(5)>
<L4>:
# .MEM_9 = VDEF <.MEM_8(D)>
price_fruit_of_the_day (p_1);
# VUSE <.MEM_9>
return;
# SUCC: EXIT [100.0%]
}
What I'm suggesting is not simply removing the directive at the source
level, but at the appropriate time using the knowledge that the block is
unreachable to simplify the CFG. In this specific case we would
eliminate block #3 and the edge from 2->3.
If we do that VRP will come along and do its thing. With the block/edge
removals, it will discover that p_6 has the value 7, p_4 is undefined
and ultimately it'll collapse the PHI into p_1 = 7. The net result (in
this case) will be the same as using builtin_unreachable.
Contrast that to simply defining away the directive per your test. In
that case we'd still have an edge from 2->3. And when that's the case,
VRP won't find a constant for p_6, which ultimately makes p_1 varying
and triggers the warning because of the use of p_4 to compute p_1.
Jeff