summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2018-02-28 23:58:05 +0000
committerJustin Lebar <jlebar@google.com>2018-02-28 23:58:05 +0000
commitfaaf2d298e033bf8cdd130a124bfc2c74fe5f046 (patch)
tree557f3e582e84c6dcab61183f6ff5b5ac7f362e14 /llvm/lib
parent5a7de898d236e2b426e050ce51fb72e382eafa28 (diff)
downloadbcm5719-llvm-faaf2d298e033bf8cdd130a124bfc2c74fe5f046.tar.gz
bcm5719-llvm-faaf2d298e033bf8cdd130a124bfc2c74fe5f046.zip
[NVPTX] Lower loads from global constants using ld.global.nc (aka LDG).
Summary: After D43914, loads from global variables in addrspace(1) happen with ld.global. But since they're constants, even better would be to use ld.global.nc, aka ldg. Reviewers: tra Subscribers: jholewinski, sanjoy, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D43915 llvm-svn: 326390
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp32
1 files changed, 18 insertions, 14 deletions
diff --git a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
index 57e2acc0d7e..b013fcf0a5c 100644
--- a/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
@@ -987,8 +987,10 @@ static bool canLowerToLDG(MemSDNode *N, const NVPTXSubtarget &Subtarget,
// We have two ways of identifying invariant loads: Loads may be explicitly
// marked as invariant, or we may infer them to be invariant.
//
- // We currently infer invariance only for kernel function pointer params that
- // are noalias (i.e. __restrict) and never written to.
+ // We currently infer invariance for loads from
+ // - constant global variables, and
+ // - kernel function pointer params that are noalias (i.e. __restrict) and
+ // never written to.
//
// TODO: Perform a more powerful invariance analysis (ideally IPO, and ideally
// not during the SelectionDAG phase).
@@ -1002,23 +1004,22 @@ static bool canLowerToLDG(MemSDNode *N, const NVPTXSubtarget &Subtarget,
if (N->isInvariant())
return true;
- // Load wasn't explicitly invariant. Attempt to infer invariance.
- if (!isKernelFunction(F->getFunction()))
- return false;
+ bool IsKernelFn = isKernelFunction(F->getFunction());
- // We use GetUnderlyingObjects() here instead of
- // GetUnderlyingObject() mainly because the former looks through phi
- // nodes while the latter does not. We need to look through phi
- // nodes to handle pointer induction variables.
+ // We use GetUnderlyingObjects() here instead of GetUnderlyingObject() mainly
+ // because the former looks through phi nodes while the latter does not. We
+ // need to look through phi nodes to handle pointer induction variables.
SmallVector<Value *, 8> Objs;
GetUnderlyingObjects(const_cast<Value *>(N->getMemOperand()->getValue()),
Objs, F->getDataLayout());
- for (Value *Obj : Objs) {
- auto *A = dyn_cast<const Argument>(Obj);
- if (!A || !A->onlyReadsMemory() || !A->hasNoAliasAttr()) return false;
- }
- return true;
+ return all_of(Objs, [&](Value *V) {
+ if (auto *A = dyn_cast<const Argument>(V))
+ return IsKernelFn && A->onlyReadsMemory() && A->hasNoAliasAttr();
+ if (auto *GV = dyn_cast<const GlobalVariable>(V))
+ return GV->isConstant();
+ return false;
+ });
}
bool NVPTXDAGToDAGISel::tryIntrinsicNoChain(SDNode *N) {
@@ -1632,6 +1633,7 @@ bool NVPTXDAGToDAGISel::tryLDGLDU(SDNode *N) {
switch (N->getOpcode()) {
default:
return false;
+ case ISD::LOAD:
case ISD::INTRINSIC_W_CHAIN:
if (IsLDG)
Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
@@ -1654,6 +1656,7 @@ bool NVPTXDAGToDAGISel::tryLDGLDU(SDNode *N) {
NVPTX::INT_PTX_LDU_GLOBAL_f32avar,
NVPTX::INT_PTX_LDU_GLOBAL_f64avar);
break;
+ case NVPTXISD::LoadV2:
case NVPTXISD::LDGV2:
Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
NVPTX::INT_PTX_LDG_G_v2i8_ELE_avar,
@@ -1676,6 +1679,7 @@ bool NVPTXDAGToDAGISel::tryLDGLDU(SDNode *N) {
NVPTX::INT_PTX_LDU_G_v2f32_ELE_avar,
NVPTX::INT_PTX_LDU_G_v2f64_ELE_avar);
break;
+ case NVPTXISD::LoadV4:
case NVPTXISD::LDGV4:
Opcode = pickOpcodeForVT(EltVT.getSimpleVT().SimpleTy,
NVPTX::INT_PTX_LDG_G_v4i8_ELE_avar,
OpenPOWER on IntegriCloud