[llvm] ae27c57 - [InferAddressSpaces] Make pass work with opaque pointers
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 26 23:57:54 PDT 2021
Author: Arthur Eubanks
Date: 2021-10-26T23:53:20-07:00
New Revision: ae27c57b1822639999a04442c372b79a30ae4a85
URL: https://github.com/llvm/llvm-project/commit/ae27c57b1822639999a04442c372b79a30ae4a85
DIFF: https://github.com/llvm/llvm-project/commit/ae27c57b1822639999a04442c372b79a30ae4a85.diff
LOG: [InferAddressSpaces] Make pass work with opaque pointers
Avoid getPointerElementType().
Added:
Modified:
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index f7d631f5e7851..4bbc0da53f814 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<GEPOperator>(CE)->getSourceElementType());
}
return CE->getWithOperands(NewOperands, TargetType);
@@ -1155,8 +1154,9 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
if (AddrSpaceCastInst *ASC = dyn_cast<AddrSpaceCastInst>(CurUser)) {
unsigned NewAS = NewV->getType()->getPointerAddressSpace();
if (ASC->getDestAddressSpace() == NewAS) {
- if (ASC->getType()->getPointerElementType() !=
- NewV->getType()->getPointerElementType()) {
+ if (!cast<PointerType>(ASC->getType())
+ ->hasSameElementTypeAs(
+ cast<PointerType>(NewV->getType()))) {
NewV = CastInst::Create(Instruction::BitCast, NewV,
ASC->getType(), "", ASC);
}
More information about the llvm-commits
mailing list