[PATCH] D91356: AMDGPU: Factor out large flat offset splitting
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 08:00:23 PST 2020
arsenm created this revision.
arsenm added reviewers: rampitec, foad.
Herald added subscribers: kerbowa, hiraditya, t-tye, tpr, dstuttard, yaxunl, nhaehnle, jvesely, kzhuravl.
Herald added a project: LLVM.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
https://reviews.llvm.org/D91356
Files:
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
Index: llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -1710,6 +1710,29 @@
llvm_unreachable("cannot find MemSDNode in the pattern!");
}
+/// Split \p COffsetVal into {immediate offset field, remainder offset} values.
+static std::pair<int64_t, int64_t> splitFlatOffset(int64_t COffsetVal,
+ const SIInstrInfo *TII,
+ unsigned AddrSpace,
+ bool IsSigned) {
+ int64_t RemainderOffset = COffsetVal;
+ int64_t ImmField = 0;
+ const unsigned NumBits = TII->getNumFlatOffsetBits(IsSigned);
+ if (IsSigned) {
+ // Use signed division by a power of two to truncate towards 0.
+ int64_t D = 1LL << (NumBits - 1);
+ RemainderOffset = (static_cast<int64_t>(COffsetVal) / D) * D;
+ ImmField = COffsetVal - RemainderOffset;
+ } else if (static_cast<int64_t>(COffsetVal) >= 0) {
+ ImmField = COffsetVal & maskTrailingOnes<uint64_t>(NumBits);
+ RemainderOffset = COffsetVal - ImmField;
+ }
+
+ assert(TII->isLegalFLATOffset(ImmField, AddrSpace, IsSigned));
+ assert(RemainderOffset + ImmField == COffsetVal);
+ return {ImmField, RemainderOffset};
+}
+
template <bool IsSigned>
bool AMDGPUDAGToDAGISel::SelectFlatOffset(SDNode *N,
SDValue Addr,
@@ -1742,22 +1765,10 @@
// into two pieces that are both >= 0 or both <= 0.
SDLoc DL(N);
- uint64_t RemainderOffset = COffsetVal;
- uint64_t ImmField = 0;
- const unsigned NumBits = TII->getNumFlatOffsetBits(IsSigned);
- if (IsSigned) {
- // Use signed division by a power of two to truncate towards 0.
- int64_t D = 1LL << (NumBits - 1);
- RemainderOffset = (static_cast<int64_t>(COffsetVal) / D) * D;
- ImmField = COffsetVal - RemainderOffset;
- } else if (static_cast<int64_t>(COffsetVal) >= 0) {
- ImmField = COffsetVal & maskTrailingOnes<uint64_t>(NumBits);
- RemainderOffset = COffsetVal - ImmField;
- }
- assert(TII->isLegalFLATOffset(ImmField, AS, IsSigned));
- assert(RemainderOffset + ImmField == COffsetVal);
+ uint64_t RemainderOffset;
- OffsetVal = ImmField;
+ std::tie(OffsetVal, RemainderOffset)
+ = splitFlatOffset(COffsetVal, TII, AS, IsSigned);
SDValue AddOffsetLo =
getMaterializedScalarImm32(Lo_32(RemainderOffset), DL);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91356.304842.patch
Type: text/x-patch
Size: 2653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201112/d11e5ec0/attachment.bin>
More information about the llvm-commits
mailing list