[llvm] [RegAlloc][RISCV] Increase the spill weight by target factor (PR #113675)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 28 04:16:14 PDT 2024


lukel97 wrote:

My bad, I was getting two things conflated. I had also tried a different approach where instead of adjusting the spill weights, I changed the eviction advisor to aggressively perform local reassignment (i.e. when trying to evict an m8 register, it would now try to evict an m1 register instead if it could be immediately assigned a register): https://github.com/lukel97/llvm-project/commit/4075bfc46cf93978d3ca87442c725e737d973546. Off the top of my head I think this was the one that led to all the spilling in SPEC (but also fixed the spilling in-tree)

But I checked out this PR locally and tried it with -march=rva23u64 -O3 -flto and still got a slight increase in the number of spills. I think with LTO there's more areas of high register pressure that this affects.

```
Program            regalloc.NumSpills                regalloc.NumReloads               
                   lhs                rhs      diff  lhs                 rhs      diff 
   531.deepsjeng_r   370.00             376.00  1.6%   793.00              800.00  0.9%
   631.deepsjeng_s   370.00             376.00  1.6%   793.00              800.00  0.9%
     538.imagick_r  4406.00            4423.00  0.4% 14425.00            14467.00  0.3%
     638.imagick_s  4406.00            4423.00  0.4% 14425.00            14467.00  0.3%
     526.blender_r 21007.00           21034.00  0.1% 47955.00            47987.00  0.1%
         602.gcc_s 19380.00           19385.00  0.0% 52642.00            52658.00  0.0%
         502.gcc_r 19380.00           19385.00  0.0% 52642.00            52658.00  0.0%
        508.namd_r  5440.00            5440.00  0.0% 12717.00            12717.00  0.0%
       641.leela_s   246.00             246.00  0.0%   482.00              482.00  0.0%
   623.xalancbmk_s  2258.00            2258.00  0.0%  4460.00             4460.00  0.0%
     620.omnetpp_s   997.00             997.00  0.0%  2837.00             2837.00  0.0%
         605.mcf_s    58.00              58.00  0.0%   107.00              107.00  0.0%
   600.perlbench_s  5432.00            5432.00  0.0% 14193.00            14193.00  0.0%
          557.xz_r   316.00             316.00  0.0%   637.00              637.00  0.0%
       541.leela_r   246.00             246.00  0.0%   482.00              482.00  0.0%
   523.xalancbmk_r  2258.00            2258.00  0.0%  4460.00             4460.00  0.0%
      510.parest_r  4565.00            4565.00  0.0% 11879.00            11879.00  0.0%
     520.omnetpp_r   997.00             997.00  0.0%  2837.00             2837.00  0.0%
         505.mcf_r    58.00              58.00  0.0%   107.00              107.00  0.0%
   500.perlbench_r  5432.00            5432.00  0.0% 14193.00            14193.00  0.0%
         644.nab_s   354.00             354.00  0.0%   787.00              787.00  0.0%
         619.lbm_s    70.00              70.00  0.0%    89.00               89.00  0.0%
         544.nab_r   354.00             354.00  0.0%   787.00              787.00  0.0%
         519.lbm_r    72.00              72.00  0.0%    91.00               91.00  0.0%
      511.povray_r  2453.00            2453.00  0.0%  5813.00             5813.00  0.0%
          657.xz_s   316.00             316.00  0.0%   637.00              637.00  0.0%
        525.x264_r  2456.00            2454.00 -0.1%  5504.00             5503.00 -0.0%
        625.x264_s  2456.00            2454.00 -0.1%  5504.00             5503.00 -0.0%
   997.specrand_fr     0.00               0.00                                         
   996.specrand_fs     0.00               0.00                                         
   999.specrand_ir     0.00               0.00                                         
   998.specrand_is     0.00               0.00                                         
Geomean difference                              0.1%                               0.1%
```

With that said, I'm not sure if these spills or reloads are signficant for performance. And on the llvm-test-suite loop vectorization micro benchmarks it actually removes all of the spills.

```
                   test-suite :: MicroBenchmarks/LoopVectorization/LoopVectorizationBenchmarks.test   391.00               0.00 -100.0%   905.00                     -100.0%
                    test-suite :: MicroBenchmarks/LoopVectorization/LoopInterleavingBenchmarks.test   391.00               0.00 -100.0%   905.00                     -100.0%
```

I will try and a do a run on deepsjeng and imagick to check this, but I would be overall in favour of this. 

> I wanted to scale the weight by the number of physical registers, which is accidentally the register class weight.

For what it's worth, I also previously tried scaling it by the number of reg units: https://github.com/lukel97/llvm-project/commit/65bd27ec3db908ee24abd40539508875800165df 

But I think this might actually be the same thing that the reg class weight should reflect?

```
  // Weight override for register pressure calculation. This is the value
  // TargetRegisterClass::getRegClassWeight() will return. The weight is in
  // units of pressure for this register class. If unset tablegen will
  // calculate a weight based on a number of register units in this register
  // class registers. The weight is per register.
  int Weight = ?;
```

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


More information about the llvm-commits mailing list