diff options
author | Nikita Popov <npopov@redhat.com> | 2024-01-12 14:21:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-12 14:21:21 +0100 |
commit | 6c2fbc3a68ba6d4bd1c8c2c43c98cff5e82f2ba4 (patch) | |
tree | e29da579fba2853f341b9f6c99f6701d73a8b0be /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | ae5d63924a6214154194c286a13c6ae74d31c086 (diff) | |
download | llvm-6c2fbc3a68ba6d4bd1c8c2c43c98cff5e82f2ba4.zip llvm-6c2fbc3a68ba6d4bd1c8c2c43c98cff5e82f2ba4.tar.gz llvm-6c2fbc3a68ba6d4bd1c8c2c43c98cff5e82f2ba4.tar.bz2 |
[IRBuilder] Add CreatePtrAdd() method (NFC) (#77582)
This abstracts over the common pattern of creating a gep with i8 element
type.
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index b8bfb97..ff61f1a 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -5553,7 +5553,6 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, } else { Type *I8PtrTy = Builder.getPtrTy(Addr->getType()->getPointerAddressSpace()); - Type *I8Ty = Builder.getInt8Ty(); // Start with the base register. Do this first so that subsequent address // matching finds it last, which will prevent it from trying to match it @@ -5597,8 +5596,8 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, // SDAG consecutive load/store merging. if (ResultPtr->getType() != I8PtrTy) ResultPtr = Builder.CreatePointerCast(ResultPtr, I8PtrTy); - ResultPtr = Builder.CreateGEP(I8Ty, ResultPtr, ResultIndex, - "sunkaddr", AddrMode.InBounds); + ResultPtr = Builder.CreatePtrAdd(ResultPtr, ResultIndex, "sunkaddr", + AddrMode.InBounds); } ResultIndex = V; @@ -5609,8 +5608,8 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, } else { if (ResultPtr->getType() != I8PtrTy) ResultPtr = Builder.CreatePointerCast(ResultPtr, I8PtrTy); - SunkAddr = Builder.CreateGEP(I8Ty, ResultPtr, ResultIndex, "sunkaddr", - AddrMode.InBounds); + SunkAddr = Builder.CreatePtrAdd(ResultPtr, ResultIndex, "sunkaddr", + AddrMode.InBounds); } if (SunkAddr->getType() != Addr->getType()) { @@ -6169,7 +6168,6 @@ bool CodeGenPrepare::splitLargeGEPOffsets() { Type *PtrIdxTy = DL->getIndexType(GEP->getType()); Type *I8PtrTy = PointerType::get(Ctx, GEP->getType()->getPointerAddressSpace()); - Type *I8Ty = Type::getInt8Ty(Ctx); BasicBlock::iterator NewBaseInsertPt; BasicBlock *NewBaseInsertBB; @@ -6198,7 +6196,7 @@ bool CodeGenPrepare::splitLargeGEPOffsets() { if (NewBaseGEP->getType() != I8PtrTy) NewBaseGEP = NewBaseBuilder.CreatePointerCast(NewBaseGEP, I8PtrTy); NewBaseGEP = - NewBaseBuilder.CreateGEP(I8Ty, NewBaseGEP, BaseIndex, "splitgep"); + NewBaseBuilder.CreatePtrAdd(NewBaseGEP, BaseIndex, "splitgep"); NewGEPBases.insert(NewBaseGEP); return; }; @@ -6235,9 +6233,7 @@ bool CodeGenPrepare::splitLargeGEPOffsets() { } // Generate a new GEP to replace the current one. - LLVMContext &Ctx = GEP->getContext(); Type *PtrIdxTy = DL->getIndexType(GEP->getType()); - Type *I8Ty = Type::getInt8Ty(Ctx); if (!NewBaseGEP) { // Create a new base if we don't have one yet. Find the insertion @@ -6250,7 +6246,7 @@ bool CodeGenPrepare::splitLargeGEPOffsets() { if (Offset != BaseOffset) { // Calculate the new offset for the new GEP. Value *Index = ConstantInt::get(PtrIdxTy, Offset - BaseOffset); - NewGEP = Builder.CreateGEP(I8Ty, NewBaseGEP, Index); + NewGEP = Builder.CreatePtrAdd(NewBaseGEP, Index); } replaceAllUsesWith(GEP, NewGEP, FreshBBs, IsHugeFunc); LargeOffsetGEPID.erase(GEP); |