Contributors:
- Dan Berlin
Delivery date:
- Now.
Benefits:
- Superior code generation.
Risks:
- Inferior code generation if not correctly tuned.
Description:
- Partial dead code elimination allows further sinking through phi nodes, and out of loops. It is not always a win, so it has been limited to profitable cases. Here is an example
int foo (int *, int *);
int
main (int argc)
{
int a, b, c;
b = argc + 1;
c = argc + 2;
a = b + c;
if (argc)
{
foo (&b, &c);
a = b + c;
}
printf ("%d\n", a);
}- The a = b + c can be sunk to right before the printf. Normal code sinking won't do this, it will sink the first one above into the else branch of "if (argc)", which still gives you two copies of the code. The risks of this optimization are a bit larger than the original risk of the code sinking patch I posted, because partial dead code elimination is not always a win. However, it is easily disabled if we find it not to be profitable, and we already know the original code sinking patch improves gcc bootstraps by a couple percent. The algorithm itself is O(n), so it should not present any compile time regressions.