[llvm] [InferAddressSpaces] Fix bad `addrspacecast` insertion for phinode (PR #163528)

Kerang Mao via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 19 19:01:07 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)) {
----------------
Kerang-BR wrote:

Yes, it is quite simple to insert new cast instructions in every incoming BB, but on the other hand, it seems a bit redundant. 

https://github.com/llvm/llvm-project/pull/163528


More information about the llvm-commits mailing list