-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RISCV] Added the MIPS prefetch extensions for MIPS RV64 P8700. #145647
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
Changes from 2 commits
8a1f988
ff11413
96d7bde
7962538
b83fbc0
49e4656
04aebba
60b7544
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2925,6 +2925,54 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base, | |
| return true; | ||
| } | ||
|
|
||
| /// Similar to SelectAddrRegImm, except that the offset restricted for | ||
| /// nine bits. | ||
| bool RISCVDAGToDAGISel::SelectAddrRegImm9(SDValue Addr, SDValue &Base, | ||
| SDValue &Offset) { | ||
| if (SelectAddrFrameIndex(Addr, Base, Offset)) | ||
| return true; | ||
|
|
||
| SDLoc DL(Addr); | ||
| MVT VT = Addr.getSimpleValueType(); | ||
|
|
||
| if (CurDAG->isBaseWithConstantOffset(Addr)) { | ||
|
|
||
| int64_t CVal = cast<ConstantSDNode>(Addr.getOperand(1))->getSExtValue(); | ||
| if (isUInt<9>(CVal)) { | ||
| Base = Addr.getOperand(0); | ||
|
|
||
| if (auto *FIN = dyn_cast<FrameIndexSDNode>(Base)) | ||
| Base = CurDAG->getTargetFrameIndex(FIN->getIndex(), VT); | ||
| Offset = CurDAG->getSignedTargetConstant(CVal, DL, VT); | ||
| return true; | ||
| } | ||
|
|
||
| // Handle with 12 bit ofset immediates with ADDI. | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| else if (Addr.getOpcode() == ISD::ADD && | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| isa<ConstantSDNode>(Addr.getOperand(1))) { | ||
| int64_t CVal = cast<ConstantSDNode>(Addr.getOperand(1))->getSExtValue(); | ||
| assert(!isUInt<9>(CVal) && "uimm9 not already handled?"); | ||
|
|
||
| if (isUInt<12>(CVal)) { | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Base = SDValue(CurDAG->getMachineNode( | ||
| RISCV::ADDI, DL, VT, Addr.getOperand(0), | ||
| CurDAG->getSignedTargetConstant(CVal, DL, VT)), | ||
| 0); | ||
| Offset = CurDAG->getTargetConstant(0, DL, VT); | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| // Immediates more than 12 bits i.e LUI,ADDI,ADD | ||
| if (selectConstantAddr(CurDAG, DL, VT, Subtarget, Addr, Base, Offset, | ||
|
||
| /*IsPrefetch=*/true)) | ||
| return true; | ||
|
|
||
| Base = Addr; | ||
| Offset = CurDAG->getTargetConstant(0, DL, VT); | ||
| return true; | ||
| } | ||
|
|
||
| /// Similar to SelectAddrRegImm, except that the least significant 5 bits of | ||
| /// Offset should be all zeros. | ||
| bool RISCVDAGToDAGISel::SelectAddrRegImmLsb00000(SDValue Addr, SDValue &Base, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2742,6 +2742,9 @@ bool RISCVInstrInfo::verifyInstruction(const MachineInstr &MI, | |
| case RISCVOp::OPERAND_UIMM9_LSB000: | ||
| Ok = isShiftedUInt<6, 3>(Imm); | ||
| break; | ||
| case RISCVOp::OPERAND_UIMM9: | ||
|
||
| Ok = isUInt<9>(Imm); | ||
| break; | ||
| case RISCVOp::OPERAND_SIMM10_LSB0000_NONZERO: | ||
| Ok = isShiftedInt<6, 4>(Imm) && (Imm != 0); | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -29,6 +29,12 @@ def uimm7_lsb000 : RISCVOp, | |||||
| }]; | ||||||
| } | ||||||
|
|
||||||
| // A 9-bit unsigned offset | ||||||
| def uimm9 : RISCVUImmOp<9>; | ||||||
|
|
||||||
| // Custom prefetch ADDR selector | ||||||
| def AddrRegImm9 : ComplexPattern<iPTR, 2, "SelectAddrRegImm9">; | ||||||
|
|
||||||
| //===----------------------------------------------------------------------===// | ||||||
| // MIPS custom instruction formats | ||||||
| //===----------------------------------------------------------------------===// | ||||||
|
|
@@ -103,9 +109,41 @@ class SWPFormat<dag outs, dag ins, string opcodestr, string argstr> | |||||
| let Inst{6-0} = OPC_CUSTOM_0.Value; | ||||||
| } | ||||||
|
|
||||||
| // Prefetch format. | ||||||
| let hasSideEffects = 0, mayLoad = 1,mayStore = 1 in | ||||||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| class Mips_prefetch_ri<dag outs, dag ins, string opcodestr, string argstr> | ||||||
| : RVInst<outs, ins, opcodestr, argstr, [], InstFormatI> { | ||||||
| bits<9> imm9; | ||||||
| bits<5> rs1; | ||||||
| bits<5> hint; | ||||||
|
|
||||||
| let Inst{31 - 29} = 0b000; | ||||||
|
||||||
| let Inst{28 - 20} = imm9{8 - 0}; | ||||||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| let Inst{19 - 15} = rs1; | ||||||
| let Inst{14 - 12} = 0b000; | ||||||
| let Inst{11 - 7} = hint; | ||||||
| let Inst{6 - 0} = OPC_CUSTOM_0.Value; | ||||||
| } | ||||||
|
|
||||||
| //===----------------------------------------------------------------------===// | ||||||
| // MIPS extensions | ||||||
| //===----------------------------------------------------------------------===// | ||||||
| let Predicates = [HasVendorXMIPSCBOP] ,DecoderNamespace = "Xmipscbop" in { | ||||||
| def MIPSPREFETCH : Mips_prefetch_ri<(outs),(ins GPR:$rs1, uimm9:$imm9, uimm5:$hint), | ||||||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| "mips.perf", "$hint, ${imm9}(${rs1})">, | ||||||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| Sched<[]>; | ||||||
| } | ||||||
|
|
||||||
| let Predicates = [HasVendorXMIPSCBOP] in { | ||||||
| // Prefetch Data Write. | ||||||
| def : Pat<(prefetch(AddrRegImm9(XLenVT GPR:$rs1),uimm9:$imm9), | ||||||
|
||||||
| def : Pat<(prefetch(AddrRegImm9(XLenVT GPR:$rs1),uimm9:$imm9), | |
| def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9), |
topperc marked this conversation as resolved.
Show resolved
Hide resolved
Outdated
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.
| def : Pat<(prefetch(AddrRegImm9(XLenVT GPR:$rs1),uimm9:$imm9), | |
| def : Pat<(prefetch (AddrRegImm9 (XLenVT GPR:$rs1), uimm9:$imm9), |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ; RUN: llc -mtriple=riscv32 -mattr=+xmipscbop -mattr=+m -verify-machineinstrs < %s \ | ||
ukalappa-mips marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ; RUN: | FileCheck %s -check-prefix=RV32XMIPSPREFETCH | ||
| ; RUN: llc -mtriple=riscv64 -mattr=+xmipscbop -mattr=+m -verify-machineinstrs < %s \ | ||
| ; RUN: | FileCheck %s -check-prefix=RV64XMIPSPREFETCH | ||
|
|
||
| define dso_local void @prefetch_read(ptr noundef %a) { | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ; RV32XMIPSPREFETCH-LABEL: prefetch_read: | ||
| ; RV32XMIPSPREFETCH: mips.perf 8, 511(a0) | ||
| ; | ||
| ; RV64XMIPSPREFETCH-LABEL: prefetch_read: | ||
| ; RV64XMIPSPREFETCH: mips.perf 8, 511(a0) | ||
| entry: | ||
| %a.addr = alloca ptr, align 8 | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| store ptr %a, ptr %a.addr, align 8 | ||
| %0 = load ptr, ptr %a.addr, align 8 | ||
| %arrayidx = getelementptr inbounds i8, ptr %0, i64 511 | ||
| call void @llvm.prefetch.p0(ptr %arrayidx, i32 0, i32 0, i32 1) | ||
| ret void | ||
| } | ||
|
|
||
| declare void @llvm.prefetch.p0(ptr readonly captures(none), i32 immarg, i32 immarg, i32 immarg) | ||
ukalappa-mips marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| define dso_local void @prefetch_write(ptr noundef %a) { | ||
| entry: | ||
| ; RV32XMIPSPREFETCH-LABEL: prefetch_write: | ||
| ; RV32XMIPSPREFETCH: addi a1, a0, 512 | ||
| ; RV32XMIPSPREFETCH-NEXT: mips.perf 9, 0(a1) | ||
| ; | ||
| ; RV64XMIPSPREFETCH-LABEL: prefetch_write: | ||
| ; RV64XMIPSPREFETCH: addi a1, a0, 512 | ||
| ; RV64XMIPSPREFETCH-NEXT: mips.perf 9, 0(a1) | ||
| %a.addr = alloca ptr, align 8 | ||
| store ptr %a, ptr %a.addr, align 8 | ||
| %0 = load ptr, ptr %a.addr, align 8 | ||
| %arrayidx = getelementptr inbounds i8, ptr %0, i64 512 | ||
| call void @llvm.prefetch.p0(ptr %arrayidx, i32 1, i32 0, i32 1) | ||
| ret void | ||
| } | ||
|
|
||
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.
"multiple of 9 bytes" doesn't make sense.
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.
Update the diagnostics