-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[RISCV] Use SelectAddrRegRegScale for Xqcisls instructions. #145608
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
Conversation
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesThis reuses code from XTHeadMemIdex. This saves ~500 bytes from the isel table and provides more flexibility in what patterns can be matched. Full diff: https://github.com/llvm/llvm-project/pull/145608.diff 3 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index aa1ebba567824..a25d4e67d1d73 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -502,6 +502,12 @@ def uimm6gt32 : ImmLeaf<XLenVT, [{
// Addressing modes.
def AddrRegImm : ComplexPattern<iPTR, 2, "SelectAddrRegImm">;
+class AddrRegRegScale<int N>
+ : ComplexPattern<iPTR, 3, "SelectAddrRegRegScale<"#N#">">;
+class AddrRegZextRegScale<int N>
+ : ComplexPattern<i64, 3, "SelectAddrRegZextRegScale<"#N#", 32>",
+ [], [], 10>;
+
// Return the negation of an immediate value.
def NegImm : SDNodeXForm<imm, [{
return CurDAG->getSignedTargetConstant(-N->getSExtValue(), SDLoc(N),
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
index 89441444a994e..c23a58ceccead 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td
@@ -743,32 +743,30 @@ def TH_SYNC_I : THCacheInst_void<0b11010, "th.sync.i">;
def TH_SYNC_IS : THCacheInst_void<0b11011, "th.sync.is">;
}
-def AddrRegRegScale : ComplexPattern<iPTR, 3, "SelectAddrRegRegScale<3>">;
-def AddrRegZextRegScale
- : ComplexPattern<i64, 3, "SelectAddrRegZextRegScale<3, 32>",
- [], [], 10>;
+def AddrRegRegScale3 : AddrRegRegScale<3>;
+def AddrRegZextRegScale3 : AddrRegZextRegScale<3>;
multiclass LdIdxPat<PatFrag LoadOp, RVInst Inst, ValueType vt = XLenVT> {
-def : Pat<(vt (LoadOp (AddrRegRegScale (XLenVT GPR:$rs1), (XLenVT GPR:$rs2), uimm2:$uimm2))),
+def : Pat<(vt (LoadOp (AddrRegRegScale3 (XLenVT GPR:$rs1), (XLenVT GPR:$rs2), uimm2:$uimm2))),
(Inst GPR:$rs1, GPR:$rs2, uimm2:$uimm2)>;
}
multiclass LdZextIdxPat<PatFrag LoadOp, RVInst Inst, ValueType vt = i64> {
-def : Pat<(vt (LoadOp (AddrRegZextRegScale (i64 GPR:$rs1), (i64 GPR:$rs2), uimm2:$uimm2))),
+def : Pat<(vt (LoadOp (AddrRegZextRegScale3 (i64 GPR:$rs1), (i64 GPR:$rs2), uimm2:$uimm2))),
(Inst GPR:$rs1, GPR:$rs2, uimm2:$uimm2)>;
}
multiclass StIdxPat<PatFrag StoreOp, RVInst Inst, RegisterClass StTy,
ValueType vt = XLenVT> {
def : Pat<(StoreOp (vt StTy:$rd),
- (AddrRegRegScale (XLenVT GPR:$rs1), (XLenVT GPR:$rs2), uimm2:$uimm2)),
+ (AddrRegRegScale3 (XLenVT GPR:$rs1), (XLenVT GPR:$rs2), uimm2:$uimm2)),
(Inst StTy:$rd, GPR:$rs1, GPR:$rs2, uimm2:$uimm2)>;
}
multiclass StZextIdxPat<PatFrag StoreOp, RVInst Inst, RegisterClass StTy,
ValueType vt = i64> {
def : Pat<(StoreOp (vt StTy:$rd),
- (AddrRegZextRegScale (i64 GPR:$rs1), (i64 GPR:$rs2), uimm2:$uimm2)),
+ (AddrRegZextRegScale3 (i64 GPR:$rs1), (i64 GPR:$rs2), uimm2:$uimm2)),
(Inst StTy:$rd, GPR:$rs1, GPR:$rs2, uimm2:$uimm2)>;
}
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
index b52798edbe143..460dfdbc2986f 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXqci.td
@@ -198,9 +198,6 @@ def AddLike: PatFrags<(ops node:$A, node:$B),
return CurDAG->isBaseWithConstantOffset(SDValue(N, 0));
}]>;
-def AddShl : PatFrag<(ops node:$Ra, node:$Rb, node:$SH3),
- (add node:$Ra, (shl node:$Rb, node:$SH3))>;
-
def IntCCtoQCRISCVCC : SDNodeXForm<riscv_selectcc, [{
ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(2))->get();
int64_t Imm = cast<ConstantSDNode>(N->getOperand(1))->getSExtValue();
@@ -1324,12 +1321,14 @@ class QC48StPat<PatFrag StoreOp, RVInst48 Inst>
: Pat<(StoreOp (i32 GPR:$rs2), (AddLike (i32 GPR:$rs1), simm26_nosimm12:$imm26)),
(Inst GPR:$rs2, GPR:$rs1, simm26_nosimm12:$imm26)>;
+def AddrRegRegScale7 : AddrRegRegScale<7>;
+
class QCScaledLdPat<PatFrag LoadOp, RVInst Inst>
- : Pat<(i32 (LoadOp (AddShl (i32 GPRMem:$rs1), (i32 GPRNoX0:$rs2), uimm3:$shamt))),
+ : Pat<(i32 (LoadOp (AddrRegRegScale7 (i32 GPRMem:$rs1), (i32 GPRNoX0:$rs2), uimm3:$shamt))),
(Inst GPRMem:$rs1, GPRNoX0:$rs2, uimm3:$shamt)>;
class QCScaledStPat<PatFrag StoreOp, RVInst Inst>
- : Pat<(StoreOp (i32 GPR:$rd), (AddShl (i32 GPRMem:$rs1), (i32 GPRNoX0:$rs2), uimm3:$shamt)),
+ : Pat<(StoreOp (i32 GPR:$rd), (AddrRegRegScale7 (i32 GPRMem:$rs1), (i32 GPRNoX0:$rs2), uimm3:$shamt)),
(Inst GPR:$rd, GPRMem:$rs1, GPRNoX0:$rs2, uimm3:$shamt)>;
// Match `riscv_brcc` and lower to the appropriate XQCIBI branch instruction.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! There are now more cases where we generate these instructions that we were not previously doing. I have #145644 with the test cases that show the current behavior. We can either integrate them into this PR or I can rebase my PR to show the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
72189ea
to
98f1ea3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This reuses code from XTHeadMemIdex. This saves ~500 bytes from the isel table and provides more flexibility in what patterns can be matched.
98f1ea3
to
2c4d0e9
Compare
This reuses code from XTHeadMemIdex. This saves ~500 bytes from the isel table and provides more flexibility in what patterns can be matched.