[llvm] [SPIR-V] Simplify addrspacecast for null in composite constant preprocessing (PR #192030)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 08:29:07 PDT 2026
================
@@ -1534,6 +1534,22 @@ void SPIRVEmitIntrinsics::preprocessUndefs(IRBuilder<> &B) {
}
void SPIRVEmitIntrinsics::preprocessCompositeConstants(IRBuilder<> &B) {
+ // Simplify addrspacecast(null) to ConstantPointerNull of the target type.
+ // Casting null always yields null, and this avoids SPIR-V lowering issues
+ // where the null gets typed as an integer instead of a pointer. This handles
+ // addrspacecast instructions (from expanded ConstantExprs); ConstantExpr
+ // sub-elements inside composites are simplified in the decomposition below.
+ SmallVector<Instruction *, 4> ToErase;
+ for (Instruction &I : instructions(CurrF))
+ if (auto *ASC = dyn_cast<AddrSpaceCastInst>(&I))
+ if (isa<ConstantPointerNull>(ASC->getPointerOperand())) {
+ ASC->replaceAllUsesWith(
+ ConstantPointerNull::get(cast<PointerType>(ASC->getType())));
+ ToErase.push_back(ASC);
+ }
+ for (Instruction *I : ToErase)
+ I->eraseFromParent();
----------------
jmmartinez wrote:
What if we moved this to another function? It doesn't seem related to the rest of preprocess composite constants.
PS: if we `make_early_inc_range` we should be able to avoid `ToErase`.
https://github.com/llvm/llvm-project/pull/192030
More information about the llvm-commits
mailing list