[llvm-branch-commits] [llvm] [NFCI][IR] Add DataLayout-aware `isZeroValue`/`getNullValue` and `getZeroValue` APIs (PR #183208)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 25 01:03:36 PST 2026
================
@@ -71,6 +72,27 @@ bool Constant::isNegativeZeroValue() const {
return isNullValue();
}
+// Return true iff this constant has an all-zero bit pattern.
+bool Constant::isZeroValue(const DataLayout *DL) const {
+ // When DataLayout is available, check if ConstantPointerNull actually has
+ // a zero bit pattern (it might not for non-zero-null address spaces).
+ if (DL) {
+ if (const auto *CPN = dyn_cast<ConstantPointerNull>(this))
+ return DL->isNullPointerAllZeroes(CPN->getType()->getAddressSpace());
+
+ // Check for vector splats of ConstantPointerNull.
+ if (getType()->isVectorTy()) {
+ if (const auto *SplatCPN =
+ dyn_cast_or_null<ConstantPointerNull>(getSplatValue())) {
+ return DL->isNullPointerAllZeroes(
+ SplatCPN->getType()->getAddressSpace());
+ }
+ }
+ }
+
+ return this == getZeroValue(getType());
----------------
arsenm wrote:
Probably should be directly checking the value instead of doing the constant-get-pointer-compare
https://github.com/llvm/llvm-project/pull/183208
More information about the llvm-branch-commits
mailing list