summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2017-11-30 00:52:40 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2017-11-30 00:52:40 +0000
commitcaf0ed4d74e8a3f1b05ddec05dffee3b795a72a3 (patch)
tree46750e826e58bf5dd10bde6e58c864172daef12b /llvm/lib
parenta4e418f71342da5ad67e211557971a40b13db9e8 (diff)
downloadbcm5719-llvm-caf0ed4d74e8a3f1b05ddec05dffee3b795a72a3.tar.gz
bcm5719-llvm-caf0ed4d74e8a3f1b05ddec05dffee3b795a72a3.zip
AMDGPU: Allow negative MUBUF vaddr for gfx9
GFX9 does not enable bounds checking for the resource descriptors used for private access, so it should be OK to use vaddr with a potentially negative value. llvm-svn: 319393
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp19
-rw-r--r--llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h6
2 files changed, 21 insertions, 4 deletions
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
index 836c70609c0..79d8de92031 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
@@ -1158,14 +1158,25 @@ bool AMDGPUDAGToDAGISel::SelectMUBUFScratchOffen(SDNode *Parent,
SDValue N0 = Addr.getOperand(0);
SDValue N1 = Addr.getOperand(1);
- // Offsets in vaddr must be positive.
+ // Offsets in vaddr must be positive if range checking is enabled.
//
- // The total computation of vaddr + soffset + offset must not overflow.
- // If vaddr is negative, even if offset is 0 the sgpr offset add will end up
+ // The total computation of vaddr + soffset + offset must not overflow. If
+ // vaddr is negative, even if offset is 0 the sgpr offset add will end up
// overflowing.
+ //
+ // Prior to gfx9, MUBUF instructions with the vaddr offset enabled would
+ // always perform a range check. If a negative vaddr base index was used,
+ // this would fail the range check. The overall address computation would
+ // compute a valid address, but this doesn't happen due to the range
+ // check. For out-of-bounds MUBUF loads, a 0 is returned.
+ //
+ // Therefore it should be safe to fold any VGPR offset on gfx9 into the
+ // MUBUF vaddr, but not on older subtargets which can only do this if the
+ // sign bit is known 0.
ConstantSDNode *C1 = cast<ConstantSDNode>(N1);
if (SIInstrInfo::isLegalMUBUFImmOffset(C1->getZExtValue()) &&
- CurDAG->SignBitIsZero(N0)) {
+ (!Subtarget->privateMemoryResourceIsRangeChecked() ||
+ CurDAG->SignBitIsZero(N0))) {
std::tie(VAddr, SOffset) = foldFrameIndex(N0);
ImmOffset = CurDAG->getTargetConstant(C1->getZExtValue(), DL, MVT::i16);
return true;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
index 7f7d5746af1..c1518dd3d4c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h
@@ -414,6 +414,12 @@ public:
return FlatForGlobal;
}
+ /// \returns If MUBUF instructions always perform range checking, even for
+ /// buffer resources used for private memory access.
+ bool privateMemoryResourceIsRangeChecked() const {
+ return getGeneration() < AMDGPUSubtarget::GFX9;
+ }
+
bool hasAutoWaitcntBeforeBarrier() const {
return AutoWaitcntBeforeBarrier;
}
OpenPOWER on IntegriCloud