[llvm] [ConstantRange] Bail out early in unsignedMulMayOverflow for wide integer types (PR #192275)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 17 18:00:10 PDT 2026
Firebear518 wrote:
Suggestion: Simplify the early-out conditions based on LZ
I noticed that we currently have two separate if statements for the fast paths (LZ >= BitWidth and LZ < BitWidth - 1). Since both cases ultimately just return *this * RHS, I think we can combine them into a single condition to remove a branch and reduce code duplication.
Current:
```C++
if (LZ >= BitWidth) {
Overflow = false;
return *this * RHS;
}
if (LZ < BitWidth - 1) {
Overflow = true;
return *this * RHS;
}
```
Here is what I have in mind:
```C++
if (LZ != BitWidth - 1) {
Overflow = (LZ < BitWidth - 1);
return *this * RHS;
}
```
This perfectly covers both the "no-overflow" and "guaranteed overflow" cases while keeping the borderline case (LZ == BitWidth - 1) for the slow path.
What do you think about this refactoring? I'd love to hear your thoughts!
https://github.com/llvm/llvm-project/pull/192275
More information about the llvm-commits
mailing list