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

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 1 09:32:28 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 computeForSatAddSub(/*Add*/ true, /*Signed*/ true, andResult,
+                             xorResult);
+}
----------------
goldsteinn wrote:

Why `computeForSatAddSub` as opposed to just `computeForAddSub`?
The setup implies `nsw` so I don't think you will ever sat... (likewise below, the U versions all imply `nuw` and the S versions all imply `nsw`)

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


More information about the llvm-commits mailing list