[llvm] [InferAddressSpaces] Fix null PHI operand when an incoming flat expression is not rewritten (PR #205749)

Fujun Han via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 21:53:07 PDT 2026


================
@@ -1550,9 +1550,31 @@ bool InferAddressSpacesImpl::rewriteWithNewAddressSpaces(
 
     unsigned OperandNo = PoisonUse->getOperandNo();
     assert(isa<PoisonValue>(NewV->getOperand(OperandNo)));
-    WeakTrackingVH NewOp = ValueWithNewAddrSpace.lookup(PoisonUse->get());
-    assert(NewOp &&
-           "poison replacements in ValueWithNewAddrSpace shouldn't be null");
+    Value *NewOp = ValueWithNewAddrSpace.lookup(PoisonUse->get());
+    if (!NewOp) {
+      // The operand was never rewritten into the new address space (e.g. a flat
+      // address expression in a flat-only cycle). Previously we wrote the
+      // result of the failed lookup (nullptr) straight into the clone, leaving
+      // a null operand behind. That produces invalid IR (a PHI with a null
+      // incoming value) and crashes any later consumer that walks the operands.
+      //
+      // operandWithNewAddressSpaceOrCreatePoison() is the only place that
+      // records a poison use, and it handles Constant operands before doing so,
+      // so only instructions can reach here. Mirror its predicated-addrspace
+      // path and materialize an explicit addrspacecast instead.
----------------
Peter9606 wrote:

Done — trimmed to describe only the case the fixup loop handles.

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


More information about the llvm-commits mailing list