[llvm] [SPIR-V] Simplify addrspacecast for null in composite constant preprocessing (PR #192030)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 15 08:44:28 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();
----------------
aobolensk wrote:
It makes sense, done
https://github.com/llvm/llvm-project/pull/192030
More information about the llvm-commits
mailing list