llvm-project
bc013697 - [NFCI][IR] Add DataLayout-aware `isZeroValue`/`getNullValue` and `getZeroValue` APIs

Commit
66 days ago
[NFCI][IR] Add DataLayout-aware `isZeroValue`/`getNullValue` and `getZeroValue` APIs Modify `Constant::isZeroValue()` and `Constant::getNullValue()` to accept an optional `const DataLayout *DL = nullptr` parameter, and add a new `Constant::getZeroValue()` factory method. This establishes the API distinction between "null value" (semantic null pointer, which may be non-zero on some targets) and "zero value" (all-zero bits). When DataLayout is provided: - `isZeroValue()` checks `ConstantPointerNull` against the target's null pointer bit pattern via `DL->isNullPointerAllZeroes(AS)`, returning false for address spaces where null is not zero. - `getNullValue()` constructs aggregates element-by-element when they contain pointer elements in non-zero-null address spaces, preserving ConstantPointerNull instead of collapsing to ConstantAggregateZero. When DataLayout is not provided, both functions behave identically to their previous implementations, ensuring full backward compatibility. `getZeroValue()` currently delegates to `getNullValue()` and will return a distinct zero-valued pointer constant (via `inttoptr`) once constant folding is made DataLayout-aware in a follow-up patch.
Author
Committer
Parents
Loading