[WIP][IR][Constants] Change the semantic of ConstantPointerNull to represent an actual nullptr instead of a zero-value pointer - #183215
Conversation
DataLayout through ConstantFold; fix CAZ extraction and aggregate collapse
#183209
ConstantPointerNull to represent an actual nullptr instead of a zero-value pointer
🐧 Linux x64 Test Results
All executed tests passed, but another part of the build failed. Click on a failure below to see the details. lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.olib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.olib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.oIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
🪟 Windows x64 Test Results
All executed tests passed, but another part of the build failed. Click on a failure below to see the details. [code=1] lib/Target/Hexagon/CMakeFiles/LLVMHexagonCodeGen.dir/HexagonVectorCombine.cpp.obj[code=1] lib/Target/SPIRV/CMakeFiles/LLVMSPIRVCodeGen.dir/SPIRVLegalizeZeroSizeArrays.cpp.obj[code=1] lib/Target/WebAssembly/CMakeFiles/LLVMWebAssemblyCodeGen.dir/WebAssemblyRegStackify.cpp.objIf these failures are unrelated to your changes (for example tests are broken or flaky at HEAD), please open an issue at https://github.com/llvm/llvm-project/issues and add the |
|
I wonder, would this (perhaps with additional work?) eventually allow Wasm's Wasm uses non-integral address spaces to represent |
I'm not familiar with WASM, but the ideal here is, the |
| if (isa<ConstantPointerNull>(C)) { | ||
| const APInt &NullVal = DL.getNullPtrValue(AS); | ||
| return ConstantInt::get( | ||
| DestTy, NullVal.zextOrTrunc(DestTy->getIntegerBitWidth())); |
There was a problem hiding this comment.
Why zext or trunc? I'd expect a -1 pointer to be sign extended to -1
| if (isa<ConstantPointerNull>(V)) { | ||
| const APInt &NullVal = DL->getNullPtrValue(AS); | ||
| return ConstantInt::get( | ||
| DestTy, NullVal.zextOrTrunc(DestTy->getIntegerBitWidth())); |
| case Type::PointerTyID: | ||
| return ConstantPointerNull::get(cast<PointerType>(Ty)); | ||
| case Type::PointerTyID: { | ||
| auto *Zero = ConstantInt::get(Type::getInt8Ty(Ty->getContext()), 0); |
|
I also want to get feedback on options to represent a real zero-value pointer. This PR stack chose to use |
|
inttoptr 0 seems fine to me. If 0 isn't the null value, 0 isn't special relative to any other integer value |

This WIP PR stack basically shows how the changes would pan out. It will be easier to review the changes than #166667.
DataLayout *in those functions, the constant folding will have to be conservative.Constant::getthat need to be updated to passDataLayout *into the function call. That might be the most intrusive changes in this PR stack. I'd greatly appreciate any idea that can make the changes smaller or less intrusive.