llvm-project
a899485c - [NFCI][IR] Thread `DataLayout` through `ConstantFold`; fix CAZ extraction and aggregate collapse

Commit
45 days ago
[NFCI][IR] Thread `DataLayout` through `ConstantFold`; fix CAZ extraction and aggregate collapse Prepare the constant folding infrastructure for the `ConstantPointerNull` semantic change, where null may have a non-zero bit pattern. Thread `const DataLayout *DL = nullptr` through `ConstantFoldCastInstruction`, `ConstantFoldCompareInstruction`, and `ConstantFoldGetElementPtr`. When DL is present and the null pointer is not zero for the relevant address space, pointer-involving folds (e.g., ptrtoint null -> 0, icmp uge X null -> true) are deferred to the DL-aware folder instead of producing incorrect results. Without DL, behavior is unchanged. Fix `ConstantAggregateZero` element extraction to return `getZeroValue` (not `getNullValue`), ensuring CAZ always yields all-zero-bit elements regardless of the address space's null pointer value. Fix aggregate collapse checks to use `isZeroValue()` instead of `isNullValue()`. This correctly prevents collapsing aggregates of FP -0.0 (non-zero bit pattern) into `ConstantAggregateZero`, and will prevent incorrect collapse of non-zero-null `ConstantPointerNull` after the semantic change.
Author
Committer
Parents
Loading