[llvm] 26dcc7e - [amdgpu][nfc] Skip operations on padding fields in LDS struct
Jon Chesterfield via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 26 10:31:12 PDT 2022
Author: Jon Chesterfield
Date: 2022-07-26T18:31:02+01:00
New Revision: 26dcc7e64afe089c78884213ee7f56723c95cb80
URL: https://github.com/llvm/llvm-project/commit/26dcc7e64afe089c78884213ee7f56723c95cb80
DIFF: https://github.com/llvm/llvm-project/commit/26dcc7e64afe089c78884213ee7f56723c95cb80.diff
LOG: [amdgpu][nfc] Skip operations on padding fields in LDS struct
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
index b4a8766d682e..67e8130c1a49 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerModuleLDSPass.cpp
@@ -29,6 +29,7 @@
#include "AMDGPU.h"
#include "Utils/AMDGPUBaseInfo.h"
#include "Utils/AMDGPUMemoryUtils.h"
+#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/IR/Constants.h"
@@ -234,7 +235,9 @@ class AMDGPULowerModuleLDS : public ModulePass {
performOptimizedStructLayout(LayoutFields);
std::vector<GlobalVariable *> LocalVars;
+ BitVector IsPaddingField;
LocalVars.reserve(LDSVarsToTransform.size()); // will be at least this large
+ IsPaddingField.reserve(LDSVarsToTransform.size());
{
// This usually won't need to insert any padding, perhaps avoid the alloc
uint64_t CurrentOffset = 0;
@@ -256,10 +259,12 @@ class AMDGPULowerModuleLDS : public ModulePass {
M, ATy, false, GlobalValue::InternalLinkage, UndefValue::get(ATy),
"", nullptr, GlobalValue::NotThreadLocal, AMDGPUAS::LOCAL_ADDRESS,
false));
+ IsPaddingField.push_back(true);
CurrentOffset += Padding;
}
LocalVars.push_back(FGV);
+ IsPaddingField.push_back(false);
CurrentOffset += LayoutFields[I].Size;
}
}
@@ -316,7 +321,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
GlobalVariable *GV = LocalVars[I];
Constant *GEPIdx[] = {ConstantInt::get(I32, 0), ConstantInt::get(I32, I)};
Constant *GEP = ConstantExpr::getGetElementPtr(LDSTy, SGV, GEPIdx);
- if (F) {
+ if (F && !IsPaddingField[I]) {
// Replace all constant uses with instructions if they belong to the
// current kernel.
for (User *U : make_early_inc_range(GV->users())) {
@@ -333,7 +338,7 @@ class AMDGPULowerModuleLDS : public ModulePass {
} else {
GV->replaceAllUsesWith(GEP);
}
- if (GV->use_empty()) {
+ if (GV->use_empty() && !IsPaddingField[I]) {
GV->eraseFromParent();
}
@@ -347,7 +352,17 @@ class AMDGPULowerModuleLDS : public ModulePass {
MDNode *AliasScope =
AliasScopes.empty() ? nullptr : MDNode::get(Ctx, {AliasScopes[I]});
- refineUsesAlignmentAndAA(GEP, A, DL, AliasScope, NoAlias);
+ if (!IsPaddingField[I]) {
+ refineUsesAlignmentAndAA(GEP, A, DL, AliasScope, NoAlias);
+ }
+ }
+
+ for (size_t I = 0; I < LocalVars.size(); I++) {
+ if (IsPaddingField[I]) {
+ GlobalVariable *GV = LocalVars[I];
+ assert(GV->use_empty());
+ GV->eraseFromParent();
+ }
}
// This ensures the variable is allocated when called functions access it.
More information about the llvm-commits
mailing list