[clang] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

Shafik Yaghmour via cfe-commits cfe-commits at lists.llvm.org
Sun Oct 1 19:15:09 PDT 2023


================
@@ -85,6 +85,18 @@ KnownBits KnownBits::computeForAddSub(bool Add, bool NSW,
   return KnownOut;
 }
 
+KnownBits KnownBits::computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+                                         const KnownBits &Borrow) {
+  assert(Borrow.getBitWidth() == 1 && "Borrow must be 1-bit");
+
+  // LHS - RHS = LHS + ~RHS + 1
+  // Carry 1 - Borrow in ::computeForAddCarry
+  std::swap(RHS.Zero, RHS.One);
+  return ::computeForAddCarry(LHS, RHS,
+                              /*CarryZero*/ Borrow.One.getBoolValue(),
+                              /*CarryOne*/ Borrow.Zero.getBoolValue());
----------------
shafik wrote:

To be consistent with [bugprone-argument-comment](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/argument-comment.html)

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


More information about the cfe-commits mailing list