[PATCH] D128741: [RISCV] Fold (add X, [-4096, -2049]) or (add X, [2048,4096]) into load/store address during isel.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 28 17:01:01 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5dcc5254925a: [RISCV] Fold (add X, [-4096, -2049]) or (add X, [2048,4096]) into load/storeā¦ (authored by craig.topper).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128741/new/
https://reviews.llvm.org/D128741
Files:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Index: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -1852,6 +1852,26 @@
}
}
+ // Handle ADD with large immediates.
+ if (Addr.getOpcode() == ISD::ADD && isa<ConstantSDNode>(Addr.getOperand(1))) {
+ int64_t CVal = cast<ConstantSDNode>(Addr.getOperand(1))->getSExtValue();
+ assert(!isInt<12>(CVal) && "simm12 not already handled?");
+
+ if (isInt<12>(CVal / 2) && isInt<12>(CVal - CVal / 2)) {
+ // We can use an ADDI for part of the offset and fold the rest into the
+ // load/store. This mirrors the AddiPair PatFrag in RISCVInstrInfo.td.
+ int64_t Adj = CVal < 0 ? -2048 : 2047;
+ SDLoc DL(Addr);
+ MVT VT = Addr.getSimpleValueType();
+ Base = SDValue(
+ CurDAG->getMachineNode(RISCV::ADDI, DL, VT, Addr.getOperand(0),
+ CurDAG->getTargetConstant(Adj, DL, VT)),
+ 0);
+ Offset = CurDAG->getTargetConstant(CVal - Adj, DL, VT);
+ return true;
+ }
+ }
+
Base = Addr;
Offset = CurDAG->getTargetConstant(0, SDLoc(Addr), Subtarget->getXLenVT());
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128741.440814.patch
Type: text/x-patch
Size: 1245 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/6f1378dd/attachment.bin>
More information about the llvm-commits
mailing list