llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Non-power-of-2 SLP vectorization regressions (and improvements) on RISC-V

Open lukel97 opened this issue 6 months ago • 5 comments

LNT picked up a handful of regressions after the non-power-of-two SLP vectorization change #196825 : http://lnt.llvm.org/db_default/v4/nts/22

Just flagging this here as there's likely some cost modelling issues to be worked through, see

There are also some nice improvements too though, SingleSource/Benchmarks/Shootout-C++/Shootout-C++-matrix is 12% faster

lukel97 avatar May 19 '26 10:05 lukel97

@llvm/issue-subscribers-backend-risc-v

Author: Luke Lau (lukel97)

LNT picked up a handful of regressions after the non-power-of-two SLP vectorization change #196825 : http://lnt.llvm.org/db_default/v4/nts/22

Just flagging this here as there's likely some cost modelling issues to be worked through, see

There are also some nice improvements too though, SingleSource/Benchmarks/Shootout-C++/Shootout-C++-matrix is 12% faster

Would be good to see some analysis/reproducers to understand the gaps

alexey-bataev avatar May 19 '26 10:05 alexey-bataev

Would be good to see some analysis/reproducers to understand the gaps

You can use the profile view to see the difference in assembly: http://lnt.llvm.org/db_default/v4/nts/profile/1339/22/19

lukel97 avatar May 19 '26 10:05 lukel97

Could you provide some more details, I do not see the difference in assembly and cannot do the analysis

alexey-bataev avatar May 30 '26 11:05 alexey-bataev

I think I have a very tentative analysis? I believe the non-pow-of-2 commit is causing the basic block (the one responsible for 100% of issued instructions) in n-body to change vector length multiple times like so

vsetivli	zero, 0x3, e64, m2, ta, ma
...
vsetivli	zero, 0x2, e64, m1, ta, ma
...
vsetivli	zero, 0x3, e64, m2, ta, ma
...
vsetivli	zero, 0x2, e64, m1, ta, ma
...
vsetivli	zero, 0x3, e64, m2, ta, ma
...
vsetivli	zero, 0x2, e64, m1, ta, ma
...

And this repeats a bit more.

I think this basic block was initially two basic blocks, with each block having a different vector length, but got merged into one after link-time optimization, and perhaps unrolled.

The previous build is just using one vector length throughout the whole block.

KavinTheG avatar May 30 '26 14:05 KavinTheG