Skip to content

[RISCV][VLOPT] Move mayReadPastVL check into getMinimumVLForUser. NFC #127972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

lukel97
Copy link
Contributor

@lukel97 lukel97 commented Feb 20, 2025

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.

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.
@llvmbot
Copy link
Member

llvmbot commented Feb 20, 2025

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

Author: Luke Lau (lukel97)

Changes

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 --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;

Copy link
Contributor

@wangpc-pp wangpc-pp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@lukel97 lukel97 merged commit f4f7c71 into llvm:main Feb 20, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants