[llvm] [KnownBits] Make abdu and abds optimal (PR #89081)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 18 02:08:42 PDT 2024
================
@@ -232,41 +232,53 @@ KnownBits KnownBits::smin(const KnownBits &LHS, const KnownBits &RHS) {
}
KnownBits KnownBits::abdu(const KnownBits &LHS, const KnownBits &RHS) {
- // abdu(LHS,RHS) = sub(umax(LHS,RHS), umin(LHS,RHS)).
- KnownBits UMaxValue = umax(LHS, RHS);
- KnownBits UMinValue = umin(LHS, RHS);
- KnownBits MinMaxDiff = computeForAddSub(/*Add=*/false, /*NSW=*/false,
- /*NUW=*/true, UMaxValue, UMinValue);
+ // If we know which argument is larger, return (sub LHS, RHS) or
+ // (sub RHS, LHS) directly.
+ if (LHS.getMinValue().uge(RHS.getMaxValue()))
+ return computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, LHS,
+ RHS);
+ if (RHS.getMinValue().uge(LHS.getMaxValue()))
+ return computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, RHS,
+ LHS);
----------------
jayfoad wrote:
Incidentally, if `computeForAddSub(/*NUW=*/true)` reliably detected conflict _and_ returned a proper conflict value, then these special cases would be unnecessary. It would just fall out from the `intersectWith` case below.
https://github.com/llvm/llvm-project/pull/89081
More information about the llvm-commits
mailing list