[llvm] [RISCV] Support postRA vsetvl insertion pass (PR #70549)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 22 00:17:28 PDT 2024


================
@@ -1519,6 +1677,24 @@ void RISCVInsertVSETVLI::doLocalPostpass(MachineBasicBlock &MBB) {
       Used.demandVL();
 
     if (NextMI) {
+
+      // A tail undefined vmv.v.i/x or vfmv.v.f with VL=1 can be treated in the
+      // same semantically as vmv.s.x.
+      if (MIInBetween.size() == 1 && isScalarSplatInstr(*MIInBetween[0]) &&
+          MI.getOperand(1).isImm() && MI.getOperand(1).getImm() == 1 &&
+          isLMUL1OrSmaller(RISCVVType::getVLMUL(MI.getOperand(2).getImm())) &&
+          hasUndefinedMergeOp(*MIInBetween[0], *MRI, LIS)) {
+        Used.LMUL = false;
+        Used.SEWLMULRatio = false;
+        Used.VLAny = false;
+        if (isFloatScalarMoveOrScalarSplatInstr(*MIInBetween[0]) &&
+            !ST->hasVInstructionsF64())
+          Used.SEW = DemandedFields::SEWGreaterThanOrEqualAndLessThan64;
+        else
+          Used.SEW = DemandedFields::SEWGreaterThanOrEqual;
+        Used.TailPolicy = false;
+      }
----------------
lukel97 wrote:

I tried applying this change to main on its own and it doesn't affect the in-tree tests. From the diff you linked though in https://github.com/llvm/llvm-project/commit/d83c300cd927df4233310cbaacb6f4563217b612, it seems to be caused by the vmv.v.i being scheduled differently. Presumably because there's now no vsetvlis during pre-ra scheduling.

Would post RA scheduling help in this case? cc @michaelmaitland 

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


More information about the llvm-commits mailing list