diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2024-03-12 12:10:30 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-12 12:10:30 +0000 |
commit | ffe41819e58365dfbe85a22556c0d9d284e746b9 (patch) | |
tree | 1c2e3bc4ddd9b3f6708193350107300ac1e98c6b /llvm/lib/Support/KnownBits.cpp | |
parent | 4e3310a81391fbc283d263715a68d8732e73d01d (diff) | |
download | llvm-ffe41819e58365dfbe85a22556c0d9d284e746b9.zip llvm-ffe41819e58365dfbe85a22556c0d9d284e746b9.tar.gz llvm-ffe41819e58365dfbe85a22556c0d9d284e746b9.tar.bz2 |
[Support] Add KnownBits::abds signed absolute difference and rename absdiff -> abdu (#84897)
When I created KnownBits::absdiff, I totally missed that we already have ISD::ABDS/ABDU nodes, and we use this term in other places/targets as well.
I've added the KnownBits::abds implementation and renamed KnownBits::absdiff to KnownBits::abdu.
Followup to #84791
Diffstat (limited to 'llvm/lib/Support/KnownBits.cpp')
-rw-r--r-- | llvm/lib/Support/KnownBits.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp index c33c368..d72355d 100644 --- a/llvm/lib/Support/KnownBits.cpp +++ b/llvm/lib/Support/KnownBits.cpp @@ -231,8 +231,8 @@ 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 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, @@ -250,6 +250,25 @@ KnownBits KnownBits::absdiff(const KnownBits &LHS, const KnownBits &RHS) { return KnownAbsDiff; } +KnownBits KnownBits::abds(const KnownBits &LHS, const KnownBits &RHS) { + // abds(LHS,RHS) = sub(smax(LHS,RHS), smin(LHS,RHS)). + KnownBits SMaxValue = smax(LHS, RHS); + KnownBits SMinValue = smin(LHS, RHS); + KnownBits MinMaxDiff = computeForAddSub(/*Add=*/false, /*NSW=*/false, + /*NUW=*/false, SMaxValue, SMinValue); + + // find the common bits between sub(LHS,RHS) and sub(RHS,LHS). + KnownBits Diff0 = + computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, LHS, RHS); + KnownBits Diff1 = + computeForAddSub(/*Add=*/false, /*NSW=*/false, /*NUW=*/false, RHS, LHS); + KnownBits SubDiff = Diff0.intersectWith(Diff1); + + KnownBits KnownAbsDiff = MinMaxDiff.unionWith(SubDiff); + assert(!KnownAbsDiff.hasConflict() && "Bad Output"); + return KnownAbsDiff; +} + static unsigned getMaxShiftAmount(const APInt &MaxValue, unsigned BitWidth) { if (isPowerOf2_32(BitWidth)) return MaxValue.extractBitsAsZExtValue(Log2_32(BitWidth), 0); |