Skip to content

Commit 0680795

Browse files
committed
[llvm] Remove uses of hasSameElemenTypeAs() (NFC)
Always returns true with opaque pointers.
1 parent 61e0822 commit 0680795

File tree

3 files changed

+3
-38
lines changed

3 files changed

+3
-38
lines changed

llvm/lib/IR/Constants.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,21 +2226,6 @@ Constant *ConstantExpr::getAddrSpaceCast(Constant *C, Type *DstTy,
22262226
bool OnlyIfReduced) {
22272227
assert(CastInst::castIsValid(Instruction::AddrSpaceCast, C, DstTy) &&
22282228
"Invalid constantexpr addrspacecast!");
2229-
2230-
// Canonicalize addrspacecasts between different pointer types by first
2231-
// bitcasting the pointer type and then converting the address space.
2232-
PointerType *SrcScalarTy = cast<PointerType>(C->getType()->getScalarType());
2233-
PointerType *DstScalarTy = cast<PointerType>(DstTy->getScalarType());
2234-
if (!SrcScalarTy->hasSameElementTypeAs(DstScalarTy)) {
2235-
Type *MidTy = PointerType::getWithSamePointeeType(
2236-
DstScalarTy, SrcScalarTy->getAddressSpace());
2237-
if (VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2238-
// Handle vectors of pointers.
2239-
MidTy = FixedVectorType::get(MidTy,
2240-
cast<FixedVectorType>(VT)->getNumElements());
2241-
}
2242-
C = getBitCast(C, MidTy);
2243-
}
22442229
return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
22452230
}
22462231

llvm/lib/IR/Instructions.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3397,15 +3397,9 @@ unsigned CastInst::isEliminableCastPair(
33973397
"Illegal addrspacecast, bitcast sequence!");
33983398
// Allowed, use first cast's opcode
33993399
return firstOp;
3400-
case 14: {
3401-
// bitcast, addrspacecast -> addrspacecast if the element type of
3402-
// bitcast's source is the same as that of addrspacecast's destination.
3403-
PointerType *SrcPtrTy = cast<PointerType>(SrcTy->getScalarType());
3404-
PointerType *DstPtrTy = cast<PointerType>(DstTy->getScalarType());
3405-
if (SrcPtrTy->hasSameElementTypeAs(DstPtrTy))
3406-
return Instruction::AddrSpaceCast;
3407-
return 0;
3408-
}
3400+
case 14:
3401+
// bitcast, addrspacecast -> addrspacecast
3402+
return Instruction::AddrSpaceCast;
34093403
case 15:
34103404
// FIXME: this state can be merged with (1), but the following assert
34113405
// is useful to check the correcteness of the sequence due to semantic

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,20 +1251,6 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
12511251
if (AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(CurUser)) {
12521252
unsigned NewAS = NewV->getType()->getPointerAddressSpace();
12531253
if (ASC->getDestAddressSpace() == NewAS) {
1254-
if (!cast<PointerType>(ASC->getType()->getScalarType())
1255-
->hasSameElementTypeAs(
1256-
cast<PointerType>(NewV->getType()->getScalarType()))) {
1257-
BasicBlock::iterator InsertPos;
1258-
if (Instruction *NewVInst = dyn_cast<Instruction>(NewV))
1259-
InsertPos = std::next(NewVInst->getIterator());
1260-
else if (Instruction *VInst = dyn_cast<Instruction>(V))
1261-
InsertPos = std::next(VInst->getIterator());
1262-
else
1263-
InsertPos = ASC->getIterator();
1264-
1265-
NewV = CastInst::Create(Instruction::BitCast, NewV,
1266-
ASC->getType(), "", &*InsertPos);
1267-
}
12681254
ASC->replaceAllUsesWith(NewV);
12691255
DeadInstructions.push_back(ASC);
12701256
continue;

0 commit comments

Comments
 (0)