[llvm] [KnownBits] Add KnownBits::absdiff to compute the absolute difference of 2 unsigned values (PR #82354)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 10:18:06 PST 2024
================
@@ -176,6 +176,23 @@ KnownBits KnownBits::smin(const KnownBits &LHS, const KnownBits &RHS) {
return Flip(umax(Flip(LHS), Flip(RHS)));
}
+KnownBits KnownBits::absdiff(const KnownBits &LHS, const KnownBits &RHS) {
+ // absdiff(LHS,RHS) = sub(umax(LHS,RHS), umin(LHS,RHS)).
+ KnownBits UMaxValue = umax(LHS, RHS);
+ KnownBits UMinValue = umin(LHS, RHS);
+ KnownBits KnownAbsDiff = computeForAddSub(false, false, UMaxValue, UMinValue);
+
+ // fallback - find the common bits between sub(LHS,RHS) and sub(RHS,LHS).
+ if (KnownAbsDiff.isUnknown()) {
+ KnownBits Diff0 = computeForAddSub(false, false, LHS, RHS);
+ KnownBits Diff1 = computeForAddSub(false, false, RHS, LHS);
+ KnownAbsDiff = Diff0.intersectWith(Diff1);
+ }
----------------
goldsteinn wrote:
Does union of the two approaches (i.e `KnownAbsDiff = KnownAbsDiff.unionWith(Diff0.intersectWith(Diff1)`) ever provide more info even if `KnownAbsDiff` is not completely unknown?
https://github.com/llvm/llvm-project/pull/82354
More information about the llvm-commits
mailing list