[libc] [llvm] [llvm] Add KnownBits implementations for avgFloor and avgCeil (PR #86445)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 15 08:47:45 PDT 2024


================
@@ -774,6 +774,62 @@ 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) {
+  KnownBits Known = LHS;
+  KnownBits Known2 = RHS;
+  bool IsCeil = false;
+  bool IsSigned = true;
+  unsigned BitWidth = Known.getBitWidth();
+  Known = IsSigned ? Known.sext(BitWidth + 1) : Known.zext(BitWidth + 1);
+  Known2 = IsSigned ? Known2.sext(BitWidth + 1) : Known2.zext(BitWidth + 1);
+  KnownBits Carry = KnownBits::makeConstant(APInt(1, IsCeil ? 1 : 0));
+  Known = KnownBits::computeForAddCarry(Known, Known2, Carry);
+  Known = Known.extractBits(BitWidth, 1);
----------------
goldsteinn wrote:

Especially when it is generically implemented just with hardset `IsCeil` and `IsSign`.

https://github.com/llvm/llvm-project/pull/86445


More information about the llvm-commits mailing list