From 01df2fa3c427b49b60da9ea19b6c42ae13e0a134 Mon Sep 17 00:00:00 2001 From: Tom Stellard Date: Thu, 23 Jan 2014 18:49:28 +0000 Subject: R600: Unconditionally unroll loops that contain GEPs with alloca pointers Implement the getUnrollingPreferences() function for AMDGPUTargetTransformInfo so that loops that do address calculations on pointers derived from alloca are unconditionally unrolled. Unrolling these loops makes it more likely that SROA will be able to eliminate the allocas, which is a big win for R600 since memory allocated by alloca (private memory) is really slow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199916 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/R600/AMDGPUTargetTransformInfo.cpp | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'lib/Target/R600') diff --git a/lib/Target/R600/AMDGPUTargetTransformInfo.cpp b/lib/Target/R600/AMDGPUTargetTransformInfo.cpp index ca1e0b6528..a4feec7131 100644 --- a/lib/Target/R600/AMDGPUTargetTransformInfo.cpp +++ b/lib/Target/R600/AMDGPUTargetTransformInfo.cpp @@ -18,7 +18,9 @@ #define DEBUG_TYPE "AMDGPUtti" #include "AMDGPU.h" #include "AMDGPUTargetMachine.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/TargetTransformInfo.h" +#include "llvm/Analysis/ValueTracking.h" #include "llvm/Support/Debug.h" #include "llvm/Target/CostTable.h" #include "llvm/Target/TargetLowering.h" @@ -73,6 +75,8 @@ public: virtual bool hasBranchDivergence() const; + virtual void getUnrollingPreferences(Loop *L, UnrollingPreferences &UP) const; + /// @} }; @@ -88,3 +92,28 @@ llvm::createAMDGPUTargetTransformInfoPass(const AMDGPUTargetMachine *TM) { } bool AMDGPUTTI::hasBranchDivergence() const { return true; } + +void AMDGPUTTI::getUnrollingPreferences(Loop *L, + UnrollingPreferences &UP) const { + for (Loop::block_iterator BI = L->block_begin(), BE = L->block_end(); + BI != BE; ++BI) { + BasicBlock *BB = *BI; + for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); + I != E; ++I) { + const GetElementPtrInst *GEP = dyn_cast(I); + if (!GEP) + continue; + const Value *Ptr = GEP->getPointerOperand(); + const AllocaInst *Alloca = dyn_cast(GetUnderlyingObject(Ptr)); + if (Alloca) { + // We want to do whatever we can to limit the number of alloca + // instructions that make it through to the code generator. allocas + // require us to use indirect addressing, which is slow and prone to + // compiler bugs. If this loop does an address calculation on an + // alloca ptr, then we want to unconditionally unroll the loop. In most + // cases, this will make it possible for SROA to eliminate these allocas. + UP.Threshold = UINT_MAX; + } + } + } +} -- cgit v1.2.3