[llvm] [SimplifyCFG] Preserve common TBAA metadata when hoisting instructions. (PR #97158)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 9 13:18:52 PDT 2024


fhahn wrote:

> > > This would get automatically handled if it used the actual hoisting logic -- why doesn't it?
> > 
> > 
> > Do you mean `hoistCommonCodeFromSuccessors`? The code in `FoldTwoEntryPHINode` hoist any code, not just common code. The current logic however only preserves TBAA metadata across common instructions for now
> 
> Right. My point here is that if hoisting is possible, we should hoist instead of performing this transform. What you are proposing here is an odd middle ground where we keep the metadata as if we were hoisting, but still have two separate instructions for the two branches.
> 
> I assume the motivation here is that FoldTwoEntryPHINode is performed in early SimplifyCFG runs that do not enable hoisting -- I think the correct way to address this issue is to perform hoisting in the cases where it is possible and where FoldTwoEntryPHINode thinks its profitable, as what hoisting does is strictly better.
> 
> The lazy way to do that would be to try calling hoistCommonCodeFromSuccessors() after FoldTwoEntryPHINode's profitability checks. The proper way to do it would be something like allowing early hoisting if it will hoist out all instructions including terminator (we already have an exception to allow early hoisting of just terminators).

Thanks, updated this PR to relax `EqTermsOnly` to allow hoisting for equivalent instructions. Could also limit to cases with 2 successors, similarly to `FoldTwoEntryPHINode`. Is that along the lines you had in mind?


Impact on `simplifycfg.NumHoistCommonInstrs`

```
Tests: 2074
Same hash: 2023 (filtered out)
Remaining: 51
Metric: simplifycfg.NumHoistCommonInstrs

Program                                       simplifycfg.NumHoistCommonInstrs
                                              lhs                              rhs      diff
SingleSource/Benchmarks/McGill/misr               0.00                             2.00  inf%
MultiSourc...Fhourstones-3.1/fhourstones3.1       0.00                             2.00  inf%
External/S...C/CINT2006/456.hmmer/456.hmmer     409.00                           465.00 13.7%
MultiSourc...ch/office-ispell/office-ispell      94.00                           106.00 12.8%
MultiSourc...rks/BitBench/uudecode/uudecode      18.00                            20.00 11.1%
MultiSource/Benchmarks/nbench/nbench            107.00                           118.00 10.3%
External/S...FP2017rate/544.nab_r/544.nab_r     299.00                           329.00 10.0%
MultiSource/Applications/siod/siod               98.00                           106.00  8.2%
MultiSourc...olangs-C/unix-smail/unix-smail      26.00                            28.00  7.7%
MultiSource/Applications/oggenc/oggenc          562.00                           596.00  6.0%
External/S...te/520.omnetpp_r/520.omnetpp_r    3354.00                          3547.00  5.8%
MultiSourc...e/Applications/minisat/minisat      36.00                            38.00  5.6%
External/S...FP2006/482.sphinx3/482.sphinx3     223.00                           235.00  5.4%
External/S.../CFP2006/447.dealII/447.dealII    4022.00                          4220.00  4.9%
MultiSource/Benchmarks/Ptrdist/bc/bc            124.00                           130.00  4.8%
MultiSourc...e/Applications/obsequi/Obsequi      84.00                            88.00  4.8%
External/S...te/538.imagick_r/538.imagick_r    4649.00                          4858.00  4.5%
MultiSourc...sumer-typeset/consumer-typeset     572.00                           594.00  3.8%
MultiSource/Applications/treecc/treecc          422.00                           438.00  3.8%
External/S...NT2017rate/502.gcc_r/502.gcc_r   13107.00                         13594.00  3.7%
External/SPEC/CFP2006/444.namd/444.namd         110.00                           114.00  3.6%
MultiSourc...e/Applications/sqlite3/sqlite3     581.00                           601.00  3.4%
External/S...17rate/541.leela_r/541.leela_r     299.00                           309.00  3.3%
External/SPEC/CFP2006/433.milc/433.milc         184.00                           190.00  3.3%
MultiSourc...gs-C/TimberWolfMC/timberwolfmc     564.00                           582.00  3.2%
MultiSourc...ity-blowfish/security-blowfish      74.00                            76.00  2.7%
MultiSourc.../mediabench/jpeg/jpeg-6a/cjpeg     451.00                           463.00  2.7%
MultiSourc...Benchmarks/Ptrdist/yacr2/yacr2     152.00                           156.00  2.6%
External/S...NT2006/464.h264ref/464.h264ref    5319.00                          5457.00  2.6%
MultiSourc...e/Applications/ClamAV/clamscan    1235.00                          1267.00  2.6%
External/S...rate/511.povray_r/511.povray_r    1727.00                          1765.00  2.2%
External/S.../CFP2006/453.povray/453.povray    1757.00                          1795.00  2.2%
MultiSourc...ch/consumer-jpeg/consumer-jpeg     477.00                           487.00  2.1%
MultiSourc.../Applications/JM/lencod/lencod    5711.00                          5823.00  2.0%
External/S...06/400.perlbench/400.perlbench    2354.00                          2398.00  1.9%
External/S.../CFP2006/450.soplex/450.soplex    1301.00                          1325.00  1.8%
External/SPEC/CINT2006/403.gcc/403.gcc         6182.00                          6281.00  1.6%
External/S...06/483.xalancbmk/483.xalancbmk    4147.00                          4203.00  1.4%
External/S...23.xalancbmk_r/523.xalancbmk_r    5648.00                          5712.00  1.1%
External/S...00.perlbench_r/500.perlbench_r    5274.00                          5324.00  0.9%
MultiSourc.../MallocBench/espresso/espresso     244.00                           246.00  0.8%
MultiSource/Applications/d/make_dparser         528.00                           532.00  0.8%
MultiSourc.../DOE-ProxyApps-C++/CLAMR/CLAMR     811.00                           817.00  0.7%
MultiSourc...ks/ASCI_Purple/SMG2000/smg2000    1504.00                          1510.00  0.4%
MultiSourc...Benchmarks/7zip/7zip-benchmark    2623.00                          2633.00  0.4%
External/S...te/526.blender_r/526.blender_r   27768.00                         27835.00  0.2%
MultiSource/Applications/kimwitu++/kc          1146.00                          1148.00  0.2%
MultiSourc...enchmarks/VersaBench/dbms/dbms      28.00                            28.00  0.0%
MultiSource/Applications/SPASS/SPASS           1213.00                          1209.00 -0.3%
External/S...C/CINT2006/445.gobmk/445.gobmk    1396.00                          1384.00 -0.9%
SingleSour.../execute/GCC-C-execute-pr90949       0.00                             0.00
```

https://github.com/llvm/llvm-project/pull/97158


More information about the llvm-commits mailing list