[llvm] InferAddressSpaces: Stop trying to insert pointer bitcasts (PR #140873)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed May 21 02:53:14 PDT 2025
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/140873
None
>From 3f6f500e2b8c07d3f10ba9960f19dd7cebf08bc7 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 21 May 2025 11:33:53 +0200
Subject: [PATCH] InferAddressSpaces: Stop trying to insert pointer bitcasts
---
llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
index d3771c0903456..1b7cecc7ceb6a 100644
--- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -660,8 +660,6 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
// Therefore, the inferred address space must be the source space, according
// to our algorithm.
assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace);
- if (Src->getType() != NewPtrType)
- return new BitCastInst(Src, NewPtrType);
return Src;
}
@@ -739,7 +737,7 @@ Value *InferAddressSpacesImpl::cloneInstructionWithNewAddressSpace(
// If we had a no-op inttoptr/ptrtoint pair, we may still have inferred a
// source address space from a generic pointer source need to insert a cast
// back.
- return CastInst::CreatePointerBitCastOrAddrSpaceCast(Src, NewPtrType);
+ return new AddrSpaceCastInst(Src, NewPtrType);
}
default:
llvm_unreachable("Unexpected opcode");
@@ -764,7 +762,7 @@ static Value *cloneConstantExprWithNewAddressSpace(
// to our algorithm.
assert(CE->getOperand(0)->getType()->getPointerAddressSpace() ==
NewAddrSpace);
- return ConstantExpr::getBitCast(CE->getOperand(0), TargetType);
+ return CE->getOperand(0);
}
if (CE->getOpcode() == Instruction::BitCast) {
@@ -777,7 +775,7 @@ static Value *cloneConstantExprWithNewAddressSpace(
assert(isNoopPtrIntCastPair(cast<Operator>(CE), *DL, TTI));
Constant *Src = cast<ConstantExpr>(CE->getOperand(0))->getOperand(0);
assert(Src->getType()->getPointerAddressSpace() == NewAddrSpace);
- return ConstantExpr::getBitCast(Src, TargetType);
+ return Src;
}
// Computes the operands of the new constant expression.
More information about the llvm-commits
mailing list