sdcc currently lacks generalized constant propagation. Analyzing the set of possible values (exact, or using intervals or whatever complete lattice seems appropriate) would give additional information for optimization: It would help in replacing types by cheaper types (e.g. using a cheap unsigned char where the programmer used int), or allow simpler code to be generated for singed comparisons, etc.
Philipp
This would make regression test gcc-torture-execute-960302-1.c fit into memory on pdk14.
A first proof-of-concept can now be found in the genconstprop branch.
There still are quite some bugs (some regression tests fail), and a lot of missing functionality.
As an example (actually the one I used for testing during development yesterday, so the optimization will surely perform particularly well here), a function from Dhrystone:
Gets essentially optimized to:
Once the optimizations are fully implemented, it would also change the type of
Int_Loctounsigned _BitInt(8).Typical functions most likely won't profit as much as this one, though.
As of [r14149], this has now been improved to the point were it starts being useful. E.g. it will now replace a long long addition by an unsigned _BitInt(40) one in strtoul.c from the standard library.
However, the genconstprop branch is still quite experimental. A lot falls apart for ports other than stm8 (I did nearly all my testing with stm8), and there are surely lots of bugs that the regression tests are bad at detecting (such as bug in volatile accesses).
Related
Commit: [r14149]
As of [r14179], in the genconstprop branch, generalized constant propagation can also handle some information on operand bits, and z80 codegen can make some use of it. An example:
With sufficiently high optimization settings now compiles (for z80) to:
Diff:
By now, this is essentially working in the genconstprop branch. The analysis does okay on typical code, and the information is used both in machine-independent optimizations and in code generation.
There is still potential for future improvement (relatively low-hanging fruit) though:
Still, it feels like the best way forward is to get some testing results in first, once what is now in the genconstprop branch has made it to trunk.
Basic support for intrinsic named address spaces has been added by now for pdk and mcs51.
I am also starting to see the impact on Dhrystone: For mcs51, score increased by 3.5% and code size went down by 0.2% (trunk vs. genconstprop branch). For other ports, such a change would be very little. But mcs51 hasn't seen much change in a long time. For mcs51, this means that genconstprop Dhrystone scores are higher than ever recorded before (records start just before 3.6.0), and code size hasn't been that low since before 3.9.0.