[llvm] 9e225a2 - [AMDGPU] Simplify GEP construction (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 8 12:22:05 PDT 2021
Author: Nikita Popov
Date: 2021-07-08T21:21:43+02:00
New Revision: 9e225a2a71ce43cb74283d3bcf8c9d1eb7c30bd4
URL: https://github.com/llvm/llvm-project/commit/9e225a2a71ce43cb74283d3bcf8c9d1eb7c30bd4
DIFF: https://github.com/llvm/llvm-project/commit/9e225a2a71ce43cb74283d3bcf8c9d1eb7c30bd4.diff
LOG: [AMDGPU] Simplify GEP construction (NFC)
Noticed while making a related change. This code was doing
something really peculiar: Creating an APInt by parsing a string.
And then creating a SmallVector with one element to create the
GEP.
Instead create the APInt from integers and directly pass the single
index to GetElementPtrInst::Create().
Added:
Modified:
llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
index 96778bd13713..7b6959b56145 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPrintfRuntimeBinding.cpp
@@ -371,13 +371,9 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
// store unique printf id in the buffer
//
- SmallVector<Value *, 1> ZeroIdxList;
- ConstantInt *zeroInt =
- ConstantInt::get(Ctx, APInt(32, StringRef("0"), 10));
- ZeroIdxList.push_back(zeroInt);
-
GetElementPtrInst *BufferIdx = GetElementPtrInst::Create(
- I8Ty, pcall, ZeroIdxList, "PrintBuffID", Brnch);
+ I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 0)), "PrintBuffID",
+ Brnch);
Type *idPointer = PointerType::get(I32Ty, AMDGPUAS::GLOBAL_ADDRESS);
Value *id_gep_cast =
@@ -385,14 +381,11 @@ bool AMDGPUPrintfRuntimeBindingImpl::lowerPrintfForGpu(Module &M) {
new StoreInst(ConstantInt::get(I32Ty, UniqID), id_gep_cast, Brnch);
- SmallVector<Value *, 2> FourthIdxList;
- ConstantInt *fourInt =
- ConstantInt::get(Ctx, APInt(32, StringRef("4"), 10));
-
- FourthIdxList.push_back(fourInt); // 1st 4 bytes hold the printf_id
+ // 1st 4 bytes hold the printf_id
// the following GEP is the buffer pointer
- BufferIdx = GetElementPtrInst::Create(I8Ty, pcall, FourthIdxList,
- "PrintBuffGep", Brnch);
+ BufferIdx = GetElementPtrInst::Create(
+ I8Ty, pcall, ConstantInt::get(Ctx, APInt(32, 4)), "PrintBuffGep",
+ Brnch);
Type *Int32Ty = Type::getInt32Ty(Ctx);
Type *Int64Ty = Type::getInt64Ty(Ctx);
More information about the llvm-commits
mailing list