[llvm] [RISCV][VLOPT] Move mayReadPastVL check into getMinimumVLForUser. NFC (PR #127972)

via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 20 00:57:52 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Luke Lau (lukel97)

<details>
<summary>Changes</summary>

checkUsers currently does two things, a) work out the minimum VL read by every user and b) check that the operand info of the MI and users match.

getMinimumVLForUser handles most of a), with the exception of the check for instructions that read past VL e.g. vrgather which is still in checkUsers.

This moves it into getMinimumVLForUser to keep all that logic in one place and simplifies an upcoming patch.


---
Full diff: https://github.com/llvm/llvm-project/pull/127972.diff


1 Files Affected:

- (modified) llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp (+5-5) 


``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
index 8e952f5184098..b2c5253632027 100644
--- a/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp
@@ -1271,6 +1271,11 @@ RISCVVLOptimizer::getMinimumVLForUser(MachineOperand &UserOp) {
     return std::nullopt;
   }
 
+  if (mayReadPastVL(UserMI)) {
+    LLVM_DEBUG(dbgs() << "    Abort because used by unsafe instruction\n");
+    return std::nullopt;
+  }
+
   unsigned VLOpNum = RISCVII::getVLOpNum(Desc);
   const MachineOperand &VLOp = UserMI.getOperand(VLOpNum);
   // Looking for an immediate or a register VL that isn't X0.
@@ -1333,11 +1338,6 @@ std::optional<MachineOperand> RISCVVLOptimizer::checkUsers(MachineInstr &MI) {
       continue;
     }
 
-    if (mayReadPastVL(UserMI)) {
-      LLVM_DEBUG(dbgs() << "    Abort because used by unsafe instruction\n");
-      return std::nullopt;
-    }
-
     auto VLOp = getMinimumVLForUser(UserOp);
     if (!VLOp)
       return std::nullopt;

``````````

</details>


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


More information about the llvm-commits mailing list