Cmm optimizer: propagate constants across basic block boundaries
The new constant propagation pass optimizes
fn
{
bits64 a, b;
a = 1;
b = a + a;
RET_N(b);
}
as
fn() { []
}
cc: R1 = 2;
jump (I64[Sp + 0]) ();
}
which is good. However, it fails to propagate the constants across a basic block boundary. For example, the following code
fn
{
bits64 a, b;
a = 1;
lbl:
b = a + a;
RET_N(b);
}
gets optimized as
n() { []
}
cd: _cf::I64 = 1;
goto ce;
ce: R1 = _cf::I64 + _cf::I64;
jump (I64[Sp + 0]) ();
}
To make this work we should ideally work with a better representation of instructions and their use sites than currently used in CmmOpt.hs. For example, see how simple this optimization pass is to implement in LLVM: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ConstantProp.cpp?view=markup
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.0.3 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |