[llvm] [RISCV] Add macro fusion support for the Xqci extension instructions (PR #209542)

Pengcheng Wang via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 20:24:14 PDT 2026


================
@@ -0,0 +1,120 @@
+//==---- RISCVMacroFusionXQCI.td - Macro Fusions for XQCI -----*- tablegen-*-=//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// ===---------------------------------------------------------------------===//
+// The following definitions describe macro fusion predicators applicable to
+// Xqci instructions.
+
+// Fuse two instructions where the destination register of the first
+// instruction is the same as the destination register of the second
+// instruction.
+class FirstRdEqSecondRdFusion<string name, string fieldName, string desc,
----------------
wangpc-pp wrote:

I don't think we have an existing mechanism to make a fusion post-ra only (but I think it should be easy to support it, we can just emit a check of `NoVRegs` (like the statistics) in the predicator).

For the second, given this case:
```asm
inst0 rd0, rs0
inst1 rd1, rd0, rs1 // or inst1 rd1, rs1, rd0
``` 
IIUC, you want to fuse these two instructions when `rd0` and `rd1` are the same, this is the first `TieReg<0, 0>`. These two instruction must have a data dependency so `inst1` will use `rd0`, you may want to make sure the `rd0` in `inst1` is equal to `rd1`, this can be achieved by an another `TieReg<0, 1/2>`, or `SecondInstHasSameReg<0, 1>`. But if you don't care about the position of `rd0` in `inst1`, you can ingore this.

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


More information about the llvm-commits mailing list