CPR optimisation for sum types if only one constructor is used
Inspired by #3138, it might be useful for StrAnal to detect functions such as the following where only one of the data constructors for a sum type are CPRed:
loop x = case x < 10 of True -> Left x; False -> loop (x*2)
We can usefully transform to:
$wloop x = case (case x < 10 of True -> Left x; False -> loop (x*2)) of Left y -> (# y #)
loop x = case loop x of (# y #) -> Left y
Attached patch implements this behaviour. Most of the complication in the new code occurs because adding a DataCon field to the Demand data type means that we have to define a separate IfaceDemand type for storage in interface files.
The patch validates but I haven't done any tests on nofib. I have confirmed that the new optimisation hits on some examples, though.
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 |