[llvm] [SCCP] Add support for trunc nuw range. (PR #152990)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 19:48:32 PDT 2025
================
@@ -886,22 +887,36 @@ ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
// We use the non-wrapped set code to analyze the [Lower, MaxValue) part, and
// then we do the union with [MaxValue, Upper)
if (isUpperWrapped()) {
- // If Upper is greater than or equal to MaxValue(DstTy), it covers the whole
- // truncated range.
- if (Upper.getActiveBits() > DstTySize || Upper.countr_one() == DstTySize)
+ // If Upper is greater than MaxValue(DstTy), it covers the whole truncated
+ // range.
+ if (Upper.getActiveBits() > DstTySize)
return getFull(DstTySize);
- Union = ConstantRange(APInt::getMaxValue(DstTySize),Upper.trunc(DstTySize));
- UpperDiv.setAllBits();
-
- // Union covers the MaxValue case, so return if the remaining range is just
- // MaxValue(DstTy).
- if (LowerDiv == UpperDiv)
- return Union;
+ // For nuw the two parts are: [0, Upper) \/ [Lower, MaxValue(DstTy) + 1]
----------------
dtcxzyw wrote:
```suggestion
// For nuw the two parts are: [0, Upper) \/ [Lower, MaxValue(DstTy)]
```
https://github.com/llvm/llvm-project/pull/152990
More information about the llvm-commits
mailing list