Skip to content

Commit 7c7896b

Browse files
committed
[MemCpyOpt] Remove unnecessary typed pointer handling (NFC)
Drop code inserting pointer casts. Check pointer types instead of address spaces.
1 parent e24ac11 commit 7c7896b

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,29 +1068,19 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
10681068

10691069
// We can't create address space casts here because we don't know if they're
10701070
// safe for the target.
1071-
if (cpySrc->getType()->getPointerAddressSpace() !=
1072-
cpyDest->getType()->getPointerAddressSpace())
1071+
if (cpySrc->getType() != cpyDest->getType())
10731072
return false;
10741073
for (unsigned ArgI = 0; ArgI < C->arg_size(); ++ArgI)
10751074
if (C->getArgOperand(ArgI)->stripPointerCasts() == cpySrc &&
1076-
cpySrc->getType()->getPointerAddressSpace() !=
1077-
C->getArgOperand(ArgI)->getType()->getPointerAddressSpace())
1075+
cpySrc->getType() != C->getArgOperand(ArgI)->getType())
10781076
return false;
10791077

10801078
// All the checks have passed, so do the transformation.
10811079
bool changedArgument = false;
10821080
for (unsigned ArgI = 0; ArgI < C->arg_size(); ++ArgI)
10831081
if (C->getArgOperand(ArgI)->stripPointerCasts() == cpySrc) {
1084-
Value *Dest = cpySrc->getType() == cpyDest->getType() ? cpyDest
1085-
: CastInst::CreatePointerCast(cpyDest, cpySrc->getType(),
1086-
cpyDest->getName(), C);
10871082
changedArgument = true;
1088-
if (C->getArgOperand(ArgI)->getType() == Dest->getType())
1089-
C->setArgOperand(ArgI, Dest);
1090-
else
1091-
C->setArgOperand(ArgI, CastInst::CreatePointerCast(
1092-
Dest, C->getArgOperand(ArgI)->getType(),
1093-
Dest->getName(), C));
1083+
C->setArgOperand(ArgI, cpyDest);
10941084
}
10951085

10961086
if (!changedArgument)
@@ -1855,9 +1845,8 @@ bool MemCpyOptPass::processByValArgument(CallBase &CB, unsigned ArgNo) {
18551845
DT) < *ByValAlign)
18561846
return false;
18571847

1858-
// The address space of the memcpy source must match the byval argument
1859-
if (MDep->getSource()->getType()->getPointerAddressSpace() !=
1860-
ByValArg->getType()->getPointerAddressSpace())
1848+
// The type of the memcpy source must match the byval argument
1849+
if (MDep->getSource()->getType() != ByValArg->getType())
18611850
return false;
18621851

18631852
// Verify that the copied-from memory doesn't change in between the memcpy and
@@ -1931,9 +1920,8 @@ bool MemCpyOptPass::processImmutArgument(CallBase &CB, unsigned ArgNo) {
19311920
if (!MDep || MDep->isVolatile() || AI != MDep->getDest())
19321921
return false;
19331922

1934-
// The address space of the memcpy source must match the immut argument
1935-
if (MDep->getSource()->getType()->getPointerAddressSpace() !=
1936-
ImmutArg->getType()->getPointerAddressSpace())
1923+
// The type of the memcpy source must match the immut argument
1924+
if (MDep->getSource()->getType() != ImmutArg->getType())
19371925
return false;
19381926

19391927
// 2-1. The length of the memcpy must be equal to the size of the alloca.

0 commit comments

Comments
 (0)