[llvm] [RISCV] Add Tune to DontSinkSplatOperands (PR #79199)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 23:09:27 PST 2024


================
@@ -2000,6 +2000,14 @@ bool RISCVTargetLowering::shouldSinkOperands(
   if (!I->getType()->isVectorTy() || !Subtarget.hasVInstructions())
     return false;
 
+  // Don't sink splat operands if the target prefers it. Some targets requires
+  // S2V transfer buffers and we can run out of them copying the same value
+  // repeatedly.
+  // FIXME: It could still be worth doing if it would improve vector register
+  // pressure and prevent a vector spill.
+  if (Subtarget.dontSinkSplatOperands())
----------------
topperc wrote:

The middle end LICM pass will usually hoist splats of the following form out loops.

```
%a = insertelt <vscale x 2 x i64> poison, i64 0, i32 0
%b = shufflevector <vscale x 2 x i64> %a, <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer>
```

The code in function tries to sink these splats back into loops if it would enable a .vx/.vf/.wx/.wf instruction to be formed. This tuning flag disables the sinking and leaves the splats outside the loop the way LICM left them.

This is a simple way to prevent many cases of .vx/.vf/.wx/.wf instructions in loops. But as noted in the FIXMEs it is bad for register pressure. We've been trying to write an optimization pass to do this better, but we don't have anything that gives good results yet.

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


More information about the llvm-commits mailing list