[llvm] [RISCV][llvm] Support logical comparison codegen for P extension (PR #174626)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 10:04:18 PST 2026
================
@@ -1584,6 +1584,54 @@ let Predicates = [HasStdExtP] in {
// // splat pattern
def: Pat<(XLenVecI8VT (splat_vector (XLenVT GPR:$rs2))), (PADD_BS (XLenVT X0), GPR:$rs2)>;
def: Pat<(XLenVecI16VT (splat_vector (XLenVT GPR:$rs2))), (PADD_HS (XLenVT X0), GPR:$rs2)>;
+
+ // 8/16-bit comparison patterns (result is all 1s or all 0s per element)
+ // a == b
+ def: Pat<(XLenVecI8VT (setcc (XLenVecI8VT GPR:$rs1), (XLenVecI8VT GPR:$rs2), SETEQ)),
+ (PMSEQ_B GPR:$rs1, GPR:$rs2)>;
+ def: Pat<(XLenVecI16VT (setcc (XLenVecI16VT GPR:$rs1), (XLenVecI16VT GPR:$rs2), SETEQ)),
+ (PMSEQ_H GPR:$rs1, GPR:$rs2)>;
+ // a != b => !(a == b)
+ def: Pat<(XLenVecI8VT (setcc (XLenVecI8VT GPR:$rs1), (XLenVecI8VT GPR:$rs2), SETNE)),
+ (XORI (PMSEQ_B GPR:$rs1, GPR:$rs2), -1)>;
+ def: Pat<(XLenVecI16VT (setcc (XLenVecI16VT GPR:$rs1), (XLenVecI16VT GPR:$rs2), SETNE)),
+ (XORI (PMSEQ_H GPR:$rs1, GPR:$rs2), -1)>;
+ // a < b
+ def: Pat<(XLenVecI8VT (setcc (XLenVecI8VT GPR:$rs1), (XLenVecI8VT GPR:$rs2), SETLT)),
+ (PMSLT_B GPR:$rs1, GPR:$rs2)>;
+ def: Pat<(XLenVecI8VT (setcc (XLenVecI8VT GPR:$rs1), (XLenVecI8VT GPR:$rs2), SETULT)),
+ (PMSLTU_B GPR:$rs1, GPR:$rs2)>;
+ def: Pat<(XLenVecI16VT (setcc (XLenVecI16VT GPR:$rs1), (XLenVecI16VT GPR:$rs2), SETLT)),
+ (PMSLT_H GPR:$rs1, GPR:$rs2)>;
+ def: Pat<(XLenVecI16VT (setcc (XLenVecI16VT GPR:$rs1), (XLenVecI16VT GPR:$rs2), SETULT)),
+ (PMSLTU_H GPR:$rs1, GPR:$rs2)>;
+ // a <= b => !(b < a)
+ def: Pat<(XLenVecI8VT (setcc (XLenVecI8VT GPR:$rs1), (XLenVecI8VT GPR:$rs2), SETLE)),
+ (XORI (PMSLT_B GPR:$rs2, GPR:$rs1), -1)>;
----------------
topperc wrote:
The rs1 and rs2 names belong to the instruction. They should always be `(PMSLT_B GPR:$rs1, GPR:$rs2)`. The input pattern is where the swap should occur.
https://github.com/llvm/llvm-project/pull/174626
More information about the llvm-commits
mailing list