[llvm] [RISCV] Simplify the Zibi SFB patterns. NFC (PR #216449)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 20:00:40 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Craig Topper (topperc)

<details>
<summary>Changes</summary>

Use a PatLeaf to match the valid condition codes instead of using separate patterns for each.

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


1 Files Affected:

- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td (+13-10) 


``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td b/llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td
index 409aeb4c86546..419256876f136 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoSFB.td
@@ -261,15 +261,18 @@ def PseudoCCLWU : SFBLoad;
 def PseudoCCLD : SFBLoad;
 }
 
+def ZibiCond : PatLeaf<(cond), [{
+  switch (N->get()) {
+  default:
+    return false;
+  case ISD::SETEQ:
+  case ISD::SETNE:
+    return true;
+  }
+}]>;
+
 // Zibi: select with immediate comparison folded into SFB.
 // imm5_zibi is defined in RISCVInstrInfoZibi.td (included before this file).
-class SelectZibiSFB<CondCode Cond>
-    : Pat<(riscv_selectcc (XLenVT GPR:$lhs), imm5_zibi:$cimm, Cond:$cc,
-                          (XLenVT GPR:$truev), GPR:$falsev),
-          (PseudoCCMOVGPR GPR:$falsev, GPR:$truev, (CCtoZibiBCC $cc), GPR:$lhs,
-                          imm5_zibi:$cimm)>;
-
-let Predicates = [HasStdExtZibi, HasShortForwardBranchImm] in {
-  def : SelectZibiSFB<SETEQ>;
-  def : SelectZibiSFB<SETNE>;
-} // Predicates = [HasStdExtZibi, HasShortForwardBranchImm]
+let Predicates = [HasStdExtZibi, HasShortForwardBranchImm] in
+def : Pat<(riscv_selectcc (XLenVT GPR:$lhs), imm5_zibi:$cimm, ZibiCond:$cc, (XLenVT GPR:$truev), GPR:$falsev),
+           (PseudoCCMOVGPR GPR:$falsev, GPR:$truev, (CCtoZibiBCC $cc), GPR:$lhs, imm5_zibi:$cimm)>;

``````````

</details>


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


More information about the llvm-commits mailing list