[llvm] [RISCV] Introduce pass to promote double constants to a global array (PR #160536)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 07:59:30 PDT 2025


asb wrote:

I've just pushed changes that address almost all review comments on the code directly. I will merge in main and recheck for noise from test regeneration.

Summary of changes:
* Address nits, comment suggestions, use of early continue
* Moved to MapVector to reduce number of datastructures needed and simplify logic
* Directly insert a gep with offset rather than doing it in two stages.
* Skip optnone functions
* Add IR tests
* Bail out if there's only 1 promotable constant.
* And the biggest one, is switching to always insert at the first insertion point in a BB, meaning the tricky to understand logic around ordering of phi and non-phi uses is no longer necessary. As noted below, this has an impact on the instcount results.

I found that moving to insert the constant load at the earliest insertion point in the BB actually improved some benchmarks vs before. I believe this is by chance more than anything else (showing there's definitely scope for more improvements here...) and eyeballing changes I see static codegen differences where you end up with something slightly worse. But starting with the simpler logic and implementation makes sense to me, especially as there's no negative impact on performance.

The prior version of this patch:
```
Benchmark             Unmodified baseline       Old PR version   Diff (%)
============================================================
500.perlbench_r         180668945687    180668096265     -0.00%
502.gcc_r               221274522161    221271855663     -0.00%
505.mcf_r               134656204033    134656203896     -0.00%
508.namd_r              217646645332    217616374407     -0.01%
510.parest_r            291731988950    291918658872      0.06%
511.povray_r             30983594866     31102843947      0.38%
519.lbm_r                91217999812     89029313608     -2.40%
520.omnetpp_r           137699867177    138045602824      0.25%
523.xalancbmk_r         284730719514    284728917335     -0.00%
525.x264_r              379107521547    379100249327     -0.00%
526.blender_r           659391437610    659446918055      0.01%
531.deepsjeng_r         350038121654    350038121655      0.00%
538.imagick_r           238568674979    238560766185     -0.00%
541.leela_r             405660852855    405660852859      0.00%
544.nab_r               398215801848    391380810930     -1.72%
557.xz_r                129832192047    129832192046     -0.00%
```
The version with the simplified logic (vs the same baseline):
```
Benchmark                  Baseline         This PR   Diff (%)
============================================================
============================================================
500.perlbench_r         180668945687    180666122417     -0.00%
502.gcc_r               221274522161    221277565086      0.00%
505.mcf_r               134656204033    134656204066      0.00%
508.namd_r              217646645332    216699783858     -0.44%
510.parest_r            291731988950    291916190776      0.06%
511.povray_r             30983594866     31107718817      0.40%
519.lbm_r                91217999812     87405361395     -4.18%
520.omnetpp_r           137699867177    137674535853     -0.02%
523.xalancbmk_r         284730719514    284734023366      0.00%
525.x264_r              379107521547    379100250568     -0.00%
526.blender_r           659391437610    659447919505      0.01%
531.deepsjeng_r         350038121654    350038121656      0.00%
538.imagick_r           238568674979    238560772162     -0.00%
541.leela_r             405660852855    405654701346     -0.00%
544.nab_r               398215801848    391352111262     -1.72%
557.xz_r                129832192047    129832192055      0.00%
```

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


More information about the llvm-commits mailing list