From ae27c57b1822639999a04442c372b79a30ae4a85 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Tue, 26 Oct 2021 23:41:02 -0700 Subject: [PATCH] [InferAddressSpaces] Make pass work with opaque pointers Avoid getPointerElementType(). --- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp index f7d631f..4bbc0da 100644 --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -708,9 +708,8 @@ static Value *cloneConstantExprWithNewAddressSpace( if (CE->getOpcode() == Instruction::GetElementPtr) { // Needs to specify the source type while constructing a getelementptr // constant expression. - return CE->getWithOperands( - NewOperands, TargetType, /*OnlyIfReduced=*/false, - NewOperands[0]->getType()->getPointerElementType()); + return CE->getWithOperands(NewOperands, TargetType, /*OnlyIfReduced=*/false, + cast(CE)->getSourceElementType()); } return CE->getWithOperands(NewOperands, TargetType); @@ -1155,8 +1154,9 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces( if (AddrSpaceCastInst *ASC = dyn_cast(CurUser)) { unsigned NewAS = NewV->getType()->getPointerAddressSpace(); if (ASC->getDestAddressSpace() == NewAS) { - if (ASC->getType()->getPointerElementType() != - NewV->getType()->getPointerElementType()) { + if (!cast(ASC->getType()) + ->hasSameElementTypeAs( + cast(NewV->getType()))) { NewV = CastInst::Create(Instruction::BitCast, NewV, ASC->getType(), "", ASC); } -- 2.7.4