[llvm] [llvm] Add KnownBits implementations for avgFloor and avgCeil (PR #86445)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 02:08:41 PDT 2024
================
@@ -762,6 +762,46 @@ KnownBits KnownBits::usub_sat(const KnownBits &LHS, const KnownBits &RHS) {
return computeForSatAddSub(/*Add*/ false, /*Signed*/ false, LHS, RHS);
}
+KnownBits KnownBits::avgFloorS(const KnownBits &LHS, const KnownBits &RHS) {
+ // (C1 & C2) + (C1 ^ C2).ashr(1)
+ KnownBits andResult = LHS & RHS;
+ KnownBits xorResult = LHS ^ RHS;
+ xorResult.Zero.ashrInPlace(1);
+ xorResult.One.ashrInPlace(1);
+ return computeForAddSub(/*Add*/ true, /* NSW */ true, /* NUW */ false,
+ andResult, xorResult);
+}
+
+KnownBits KnownBits::avgFloorU(const KnownBits &LHS, const KnownBits &RHS) {
+ // (C1 & C2) + (C1 ^ C2).lshr(1)
+ KnownBits andResult = LHS & RHS;
+ KnownBits xorResult = LHS ^ RHS;
+ xorResult.Zero.lshrInPlace(1);
+ xorResult.One.lshrInPlace(1);
+ return computeForAddSub(/*Add*/ true, /* NSW */ false, /* NUW */ true,
+ andResult, xorResult);
+}
+
+KnownBits KnownBits::avgCeilS(const KnownBits &LHS, const KnownBits &RHS) {
+ // (C1 | C2) - (C1 ^ C2).ashr(1)
+ KnownBits andResult = LHS | RHS;
+ KnownBits xorResult = LHS ^ RHS;
+ xorResult.Zero.ashrInPlace(1);
+ xorResult.One.ashrInPlace(1);
+ return computeForAddSub(/*Add*/ false, /* NSW */ true, /* NUW */ false,
+ andResult, xorResult);
+}
+
+KnownBits KnownBits::avgCeilU(const KnownBits &LHS, const KnownBits &RHS) {
+ // (C1 | C2) - (C1 ^ C2).lshr(1)
+ KnownBits andResult = LHS | RHS;
----------------
RKSimon wrote:
andResult -> orResult
https://github.com/llvm/llvm-project/pull/86445
More information about the llvm-commits
mailing list