Skip to content

Commit 4c60c0c

Browse files
committed
[LowerMemIntrinsics] Remove no-op ptr-to-ptr bitcasts (NFC)
Remove ptr-to-ptr bitcasts, which are unnecessary with opaque pointers enabled. Opaque pointer clean-up effort. NFC.
1 parent 740582f commit 4c60c0c

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@ void llvm::createMemCpyLoopKnownSize(
6464

6565
IRBuilder<> PLBuilder(PreLoopBB->getTerminator());
6666

67-
// Cast the Src and Dst pointers to pointers to the loop operand type (if
68-
// needed).
69-
PointerType *SrcOpType = PointerType::get(LoopOpType, SrcAS);
70-
PointerType *DstOpType = PointerType::get(LoopOpType, DstAS);
71-
if (SrcAddr->getType() != SrcOpType) {
72-
SrcAddr = PLBuilder.CreateBitCast(SrcAddr, SrcOpType);
73-
}
74-
if (DstAddr->getType() != DstOpType) {
75-
DstAddr = PLBuilder.CreateBitCast(DstAddr, DstOpType);
76-
}
77-
7867
Align PartDstAlign(commonAlignment(DstAlign, LoopOpSize));
7968
Align PartSrcAlign(commonAlignment(SrcAlign, LoopOpSize));
8069

@@ -137,27 +126,18 @@ void llvm::createMemCpyLoopKnownSize(
137126
uint64_t GepIndex = BytesCopied / OperandSize;
138127
assert(GepIndex * OperandSize == BytesCopied &&
139128
"Division should have no Remainder!");
140-
// Cast source to operand type and load
141-
PointerType *SrcPtrType = PointerType::get(OpTy, SrcAS);
142-
Value *CastedSrc = SrcAddr->getType() == SrcPtrType
143-
? SrcAddr
144-
: RBuilder.CreateBitCast(SrcAddr, SrcPtrType);
129+
145130
Value *SrcGEP = RBuilder.CreateInBoundsGEP(
146-
OpTy, CastedSrc, ConstantInt::get(TypeOfCopyLen, GepIndex));
131+
OpTy, SrcAddr, ConstantInt::get(TypeOfCopyLen, GepIndex));
147132
LoadInst *Load =
148133
RBuilder.CreateAlignedLoad(OpTy, SrcGEP, PartSrcAlign, SrcIsVolatile);
149134
if (!CanOverlap) {
150135
// Set alias scope for loads.
151136
Load->setMetadata(LLVMContext::MD_alias_scope,
152137
MDNode::get(Ctx, NewScope));
153138
}
154-
// Cast destination to operand type and store.
155-
PointerType *DstPtrType = PointerType::get(OpTy, DstAS);
156-
Value *CastedDst = DstAddr->getType() == DstPtrType
157-
? DstAddr
158-
: RBuilder.CreateBitCast(DstAddr, DstPtrType);
159139
Value *DstGEP = RBuilder.CreateInBoundsGEP(
160-
OpTy, CastedDst, ConstantInt::get(TypeOfCopyLen, GepIndex));
140+
OpTy, DstAddr, ConstantInt::get(TypeOfCopyLen, GepIndex));
161141
StoreInst *Store = RBuilder.CreateAlignedStore(Load, DstGEP, PartDstAlign,
162142
DstIsVolatile);
163143
if (!CanOverlap) {
@@ -206,15 +186,6 @@ void llvm::createMemCpyLoopUnknownSize(
206186

207187
IRBuilder<> PLBuilder(PreLoopBB->getTerminator());
208188

209-
PointerType *SrcOpType = PointerType::get(LoopOpType, SrcAS);
210-
PointerType *DstOpType = PointerType::get(LoopOpType, DstAS);
211-
if (SrcAddr->getType() != SrcOpType) {
212-
SrcAddr = PLBuilder.CreateBitCast(SrcAddr, SrcOpType);
213-
}
214-
if (DstAddr->getType() != DstOpType) {
215-
DstAddr = PLBuilder.CreateBitCast(DstAddr, DstOpType);
216-
}
217-
218189
// Calculate the loop trip count, and remaining bytes to copy after the loop.
219190
Type *CopyLenType = CopyLen->getType();
220191
IntegerType *ILengthType = dyn_cast<IntegerType>(CopyLenType);
@@ -305,22 +276,18 @@ void llvm::createMemCpyLoopUnknownSize(
305276
ResBuilder.CreatePHI(CopyLenType, 2, "residual-loop-index");
306277
ResidualIndex->addIncoming(Zero, ResHeaderBB);
307278

308-
Value *SrcAsResLoopOpType = ResBuilder.CreateBitCast(
309-
SrcAddr, PointerType::get(ResLoopOpType, SrcAS));
310-
Value *DstAsResLoopOpType = ResBuilder.CreateBitCast(
311-
DstAddr, PointerType::get(ResLoopOpType, DstAS));
312279
Value *FullOffset = ResBuilder.CreateAdd(RuntimeBytesCopied, ResidualIndex);
313-
Value *SrcGEP = ResBuilder.CreateInBoundsGEP(
314-
ResLoopOpType, SrcAsResLoopOpType, FullOffset);
280+
Value *SrcGEP =
281+
ResBuilder.CreateInBoundsGEP(ResLoopOpType, SrcAddr, FullOffset);
315282
LoadInst *Load = ResBuilder.CreateAlignedLoad(ResLoopOpType, SrcGEP,
316283
PartSrcAlign, SrcIsVolatile);
317284
if (!CanOverlap) {
318285
// Set alias scope for loads.
319286
Load->setMetadata(LLVMContext::MD_alias_scope,
320287
MDNode::get(Ctx, NewScope));
321288
}
322-
Value *DstGEP = ResBuilder.CreateInBoundsGEP(
323-
ResLoopOpType, DstAsResLoopOpType, FullOffset);
289+
Value *DstGEP =
290+
ResBuilder.CreateInBoundsGEP(ResLoopOpType, DstAddr, FullOffset);
324291
StoreInst *Store = ResBuilder.CreateAlignedStore(Load, DstGEP, PartDstAlign,
325292
DstIsVolatile);
326293
if (!CanOverlap) {

0 commit comments

Comments
 (0)