[llvm] [LTO] Run Argument Promotion before IPSCCP (PR #111163)
Hari Limaye via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 4 07:29:37 PDT 2024
hazzlim wrote:
Due to the fact that Fortran passes most arguments by reference [1], Flang lowers constant arguments passed to function/subroutines as allocas + stores. We currently fail to propagate such constants during LTO in some cases, significantly impacting performance of some key benchmarks (e.g. SPEC CPU2017 bwaves). An FIR pass was added in #73829 to fix this, but is disabled by default due to portability concerns.
The core of the issue is that these constant values passed as pointers to local objects (allocas), which are promoted to scalar constants by Argument Promotion, are not able to be propagated by IPSCCP due to this running prior to Argument Promotion in the LTO pipeline.
This patch aims to address this by running Argument Promotion before IPSCCP in the LTO pipeline. We are then able to propagate such constants successfully. This gives a performance improvement of 20.1% in SPEC CPU2017 bwaves. This particular benchmark example is illustrative of the broader scope for improving Fortran code generation; for example Fortran array descriptors frequently generate structs filled with constants passed as pointers to functions, which are currently not propagated inter-procedurally in many cases at present.
The compile time cost of this change, measured by change in instruction counts for compiling CTMark:
```
Benchmark | Change |
-----------------+---------+
7zip | +0.02% |
Bullet | +0.03% |
ClamAV | +0.04% |
SPASS | +0.03% |
consumer-typeset | +0.06% |
kimwitu++ | +0.22% |
lencod | +0.10% |
mafft | +0.09% |
sqlite3 | +0.09% |
tramp3d-v4 | -0.18% |
-----------------+---------+
GEOMEAN | 0.05% |
```
An impact of this change is that some function arguments that would previously have been specialised by Function Specialization, which is currently only enabled for pointer arguments by default, are no longer specialised due to being promoted to literal constants. To mitigate this, PR #111162 enables specialising constant literal arguments by default for recursive functions. This has negligible impact on CTMark compile times (Geomean 0.00%) for both LTO and non-LTO pipelines.
[1] https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html#Argument-passing-conventions-1
https://github.com/llvm/llvm-project/pull/111163
More information about the llvm-commits
mailing list