https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92538
Bug ID: 92538 Summary: Proposal for IPA init() constant propagation Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: erick.oc...@theobroma-systems.com CC: marxin at gcc dot gnu.org Target Milestone: --- Created attachment 47278 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47278&action=edit Patch Hello, we've been working on an lto optimization and would like to receive some feedback on this candidate patch. At the moment the patch compiles correctly when applied to master. We have some initial test cases in a separate repository and have compiled and ran a small subset of CPU 2017 benchmarks with comparable results. The proposed transformation (ipa-initcall-cp) is a variant of interprocedural constant propagation. ip-initcall-cp collects all variables with static lifetime that contain only a single write (like in the cases of initialization functions) and propagates it to reads across the whole link unit. In order to run, apply the patch and compile with `-lto -finitcall-cp`. In order for this transformation to be sound * writes that can be reached from a function pointer, * writes that can be reached from a function with outside visibility, and * writes that may happen after any read are not taken into account. In order to determine that no read happens before the write, we have to: * find the main function * find the function and basic block of the write * for each read in another function * make sure that call to write dominates all callees of the read function * for each read in the same function * make sure that write dominates read Some initial drawbacks: * We've noticed that we have to disable ipa-cp in order for ipa-initcall-cp to run successfully. This is most likely due to some issue with clones and we will need to make some design changes. The function materialize all clones fails after ipa-initcall-cp if ipa-cp is not commented out. Suggestions are welcomed. * At the moment, I still need to clean the code a bit, since it doesn't pass the standards. * I still need to add tests using the testsuite as opposed to running them myself. Some future work: * At the moment, ipa-initcall-cp only propagates values from a single write. However, we could conceivably improve this work to propagate the first n-writes and specialize functions based on the constants.