[llvm] [RISCV] Fix type inference ambiguity in SwapSysReg pattern (PR #184305)

via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 3 01:38:55 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: None (lihengda861-source)

<details>
<summary>Changes</summary>

Issue:
Building RISCVInstrInfo.td fails with the following TableGen error during the generation of RISCVGenInstrInfo.inc:
     ` error: In test: Could not infer all types in pattern!`

Root Cause:
The riscv_swap_csr node has a polymorphic result type (i32 or i64 depending on the target architecture). When used inside the SwapSysReg class pattern, TableGen's type inference engine cannot automatically deduce the exact return type solely from the GPR:$rd output, leading to the ambiguity error.

Fix:
This patch resolves the type ambiguity by explicitly wrapping the riscv_swap_csr node with XLenVT, allowing TableGen to infer the types correctly.

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


1 Files Affected:

- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+1-1) 


``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index a5c0e016aaa83..eb276ef17da75 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -2057,7 +2057,7 @@ class WriteSysRegImm<SysReg SR, list<Register> Regs>
 
 class SwapSysReg<SysReg SR, list<Register> Regs>
   : Pseudo<(outs GPR:$rd), (ins GPR:$val),
-           [(set GPR:$rd, (riscv_swap_csr (XLenVT SR.Encoding), (XLenVT GPR:$val)))]>,
+           [(set GPR:$rd, (XLenVT (riscv_swap_csr (XLenVT SR.Encoding), (XLenVT GPR:$val))))]>,
     PseudoInstExpansion<(CSRRW GPR:$rd, SR.Encoding, GPR:$val)> {
   let hasSideEffects = 0;
   let Uses = Regs;

``````````

</details>


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


More information about the llvm-commits mailing list