Skip to content

[RISCV] Check for register where immediate should be in RISCVInstrInfo::verifyInstruction. #120286

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
merged 1 commit into from
Dec 17, 2024

Conversation

topperc
Copy link
Collaborator

@topperc topperc commented Dec 17, 2024

The generic verifier will do this if the operand type is OPERAND_IMMEDIATE, but we use our own custom operand types. Immediate operands are still allowed to be globals, constant pools, blockaddress, etc. so we can't check !isImm().

Fix the same typo as #120246 which is now detected by this.

CC: @PhilippvK

…o::verifyInstruction.

The generic verifier will do this if the operand type is
OPERAND_IMMEDIATE, but we use our own custom operand types.
Immediate operands are still allowed to be globals, constant pools,
blockaddress, etc. so we can't check !isImm().

Fix the same typo as llvm#120246 which is now detected by this.
@llvmbot
Copy link
Member

llvmbot commented Dec 17, 2024

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

Author: Craig Topper (topperc)

Changes

The generic verifier will do this if the operand type is OPERAND_IMMEDIATE, but we use our own custom operand types. Immediate operands are still allowed to be globals, constant pools, blockaddress, etc. so we can't check !isImm().

Fix the same typo as #120246 which is now detected by this.

CC: @PhilippvK


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

2 Files Affected:

  • (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.cpp (+4)
  • (modified) llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td (+1-1)
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index 0944e7d461f8e5..7e0063589b6f4c 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2451,6 +2451,10 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI,
     if (OpType >= RISCVOp::OPERAND_FIRST_RISCV_IMM &&
         OpType <= RISCVOp::OPERAND_LAST_RISCV_IMM) {
       const MachineOperand &MO = MI.getOperand(Index);
+      if (MO.isReg()) {
+        ErrInfo = "Expected a non-register operand.";
+        return false;
+      }
       if (MO.isImm()) {
         int64_t Imm = MO.getImm();
         bool Ok;
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td
index 4478e246111080..b98934d8c63964 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td
@@ -698,7 +698,7 @@ let Predicates = [HasVendorXCVmem, IsRV32], AddedComplexity = 1 in {
   def : CVStriPat<post_store, CV_SW_ri_inc>;
 
   def : CVStrriPat<post_truncsti8, CV_SB_rr_inc>;
-  def : CVStrriPat<post_truncsti16, CV_SH_ri_inc>;
+  def : CVStrriPat<post_truncsti16, CV_SH_rr_inc>;
   def : CVStrriPat<post_store, CV_SW_rr_inc>;
 
   def : CVStrrPat<truncstorei8, CV_SB_rr>;

@topperc topperc merged commit 09f4492 into llvm:main Dec 17, 2024
10 checks passed
@topperc topperc deleted the pr/verifier-reg branch December 17, 2024 22:39
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