[llvm] [InferAddressSpaces] Fix bad `addrspacecast` insertion for phinode (PR #163528)
Luo Yuanke via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 17 02:39:01 PDT 2025
================
@@ -617,6 +617,41 @@ InferAddressSpacesImpl::collectFlatAddressExpressions(Function &F) const {
return Postorder;
}
+// Inserts an addrspacecast for a phi node operand, handling the proper
+// insertion position based on the operand type.
+static Value *phiNodeOperandWithNewAddressSpace(AddrSpaceCastInst *NewI,
+ Value *Operand) {
+ auto InsertBefore = [NewI](auto It) {
+ NewI->insertBefore(It);
+ NewI->setDebugLoc(It->getDebugLoc());
+ return NewI;
+ };
+
+ if (auto *Arg = dyn_cast<Argument>(Operand)) {
----------------
LuoYuanke wrote:
It may be simpler to just insert the new instruction before the terminator instruction in the incoming BB, so that we don't care the Operand is Argument, Constant, Phi or Instruction.
https://github.com/llvm/llvm-project/pull/163528
More information about the llvm-commits
mailing list