[llvm] [RISCV] Keep same SEW/LMUL ratio if possible in forward transfer (PR #69788)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 25 12:20:37 PDT 2023


================
@@ -1042,6 +1042,26 @@ void RISCVInsertVSETVLI::transferBefore(VSETVLIInfo &Info,
   if (!RISCVII::hasVLOp(TSFlags))
     return;
 
+  // If we don't use LMUL or the SEW/LMUL ratio, then adjust LMUL so that we
+  // maintain the SEW/LMUL ratio. This allows us to eliminate VL toggles in more
+  // places.
+  DemandedFields Demanded = getDemanded(MI, MRI);
+  if (!Demanded.LMUL && !Demanded.SEWLMULRatio && Info.isValid() &&
+      PrevInfo.isValid() && !Info.isUnknown() && !PrevInfo.isUnknown() &&
+      !Info.hasSameVLMAX(PrevInfo)) {
+    unsigned SEW = Info.getSEW();
+    // Fixed point value with 3 fractional bits.
+    unsigned NewRatio = (SEW * 8) / PrevInfo.getSEWLMULRatio();
+    if (NewRatio >= 1 && NewRatio <= 64) {
+      bool Fractional = NewRatio < 8;
+      RISCVII::VLMUL NewVLMul = RISCVVType::encodeLMUL(
+          Fractional ? 8 / NewRatio : NewRatio / 8, Fractional);
+      unsigned VType = Info.encodeVTYPE();
----------------
preames wrote:

Given SEW is unchanged here, I think just adding a setVLMul accessor is probably cleaner.

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


More information about the llvm-commits mailing list