[flang-commits] [flang] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

Christian Kissig via flang-commits flang-commits at lists.llvm.org
Fri Sep 29 10:10:53 PDT 2023


================
@@ -3732,14 +3732,18 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
     assert(Op.getResNo() == 0 &&
            "We only compute knownbits for the difference here.");
 
-    // TODO: Compute influence of the carry operand.
-    if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY)
-      break;
+    // With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+    KnownBits Borrow(1);
+    if (Opcode == ISD::USUBO_CARRY || Opcode == ISD::SSUBO_CARRY) {
+      Borrow = computeKnownBits(Op.getOperand(2), DemandedElts, Depth + 1);
+      // Borrow has bit width 1
+      Borrow = Borrow.zextOrTrunc(1);
----------------
christiankissig wrote:

@nikic and @goldsteinn Probably just hypothetical, but I couldn't work out whether Operand 2 is always of non-zero bit width, so went with the original suggestion for ADD ops to use zextOrTrunc(). Will change to trunc() on both of your recommendation here.

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


More information about the flang-commits mailing list