Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Support] Add KnownBits::computeForSubBorrow #65893 #67553

Closed
wants to merge 3 commits into from

Conversation

christiankissig
Copy link
Contributor

  • [Support] Add KnownBits::computeForSubBorrow
  • [CodeGen] Implement USUBC, USUBO_CARRY, and SSUBO_CARRY with KnownBits::computeForSubBorrow
  • [CodeGen] Compute unknown bits for Carry/Borrow for ADD/SUB

* Implements computeForSubBorrow as alias for computeforAddCarry. Borrow
  is expected to be 1-bit wide.
* Adds exhaustive unit test.
Computes known bits for carry/borrow for UADDO_CARRY and USUBO_CARRY
Operations. Carry/borrow are expected to be 1-bit. 0 bits are padded
with unknown.

Adds a unit test for UADDO_CARRY and USUBO_CARRY.
@llvmbot llvmbot added llvm:support llvm:SelectionDAG SelectionDAGISel as well labels Sep 27, 2023
@github-actions
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 5109cb28fda8076f057c70bd25af7ed82de1d9b7 6355b54bafcec96770624a6a5df8e0c299be8f3f -- llvm/include/llvm/Support/KnownBits.h llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/lib/Support/KnownBits.cpp llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp llvm/unittests/Support/KnownBitsTest.cpp
View the diff from clang-format here.
diff --git a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
index 0430c74f7..bb8e76a2e 100644
--- a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp
@@ -268,8 +268,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_UADDO_CARRY) {
   KnownBits Known;
 
   auto UnknownBorrow = DAG->getRegister(1, IntVT);
-  auto OpUnknownBorrow = DAG->getNode(
-      ISD::UADDO_CARRY, Loc, IntVT, N0, N1, UnknownBorrow);
+  auto OpUnknownBorrow =
+      DAG->getNode(ISD::UADDO_CARRY, Loc, IntVT, N0, N1, UnknownBorrow);
   // N0 = 0010?000
   // N1 = 01100101
   // B  =        ?
@@ -281,8 +281,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_UADDO_CARRY) {
   EXPECT_EQ(Known.One, APInt(8, 0x84));
 
   auto ZeroBorrow = DAG->getConstant(0x0, Loc, IntVT);
-  auto OpZeroBorrow = DAG->getNode(
-      ISD::UADDO_CARRY, Loc, IntVT, N0, N1, ZeroBorrow);
+  auto OpZeroBorrow =
+      DAG->getNode(ISD::UADDO_CARRY, Loc, IntVT, N0, N1, ZeroBorrow);
   // N0 = 0010?000
   // N1 = 01100101
   // B  =        0
@@ -294,8 +294,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_UADDO_CARRY) {
   EXPECT_EQ(Known.One, APInt(8, 0x85));
 
   auto OneBorrow = DAG->getConstant(0x1, Loc, IntVT);
-  auto OpOneBorrow = DAG->getNode(
-      ISD::UADDO_CARRY, Loc, IntVT, N0, N1, OneBorrow);
+  auto OpOneBorrow =
+      DAG->getNode(ISD::UADDO_CARRY, Loc, IntVT, N0, N1, OneBorrow);
   // N0 = 0010?000
   // N1 = 01100101
   // B  =        1
@@ -304,7 +304,7 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_UADDO_CARRY) {
   // Known.One  = 10000110 (0x86)
   Known = DAG->computeKnownBits(OpOneBorrow);
   EXPECT_EQ(Known.Zero, APInt(8, 0x71));
-  EXPECT_EQ(Known.One, APInt(8, 0x86)); 
+  EXPECT_EQ(Known.One, APInt(8, 0x86));
 }
 
 // Piggy-backing on the AArch64 tests to verify SelectionDAG::computeKnownBits.
@@ -331,7 +331,7 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_USUBO_CARRY) {
   SDLoc Loc;
   auto IntVT = EVT::getIntegerVT(Context, 8);
   auto N0 = DAG->getConstant(0x5a, Loc, IntVT);
-  auto UnknownOp = DAG->getRegister(0, IntVT);        // ????????
+  auto UnknownOp = DAG->getRegister(0, IntVT);         // ????????
   auto Mask1_Zero = DAG->getConstant(0x8, Loc, IntVT); // 00001000
   auto Mask1_One = DAG->getConstant(0x20, Loc, IntVT); // 00100000
   // N1 = (???????? & 00001000) | 00100000 = 0010?000
@@ -341,8 +341,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_USUBO_CARRY) {
   KnownBits Known;
 
   auto UnknownBorrow = DAG->getRegister(1, IntVT);
-  auto OpUnknownBorrow = DAG->getNode(
-      ISD::USUBO_CARRY, Loc, IntVT, N0, N1, UnknownBorrow);
+  auto OpUnknownBorrow =
+      DAG->getNode(ISD::USUBO_CARRY, Loc, IntVT, N0, N1, UnknownBorrow);
   // N0 = 01011010
   // N1 = 0010?000
   // B  =        ?
@@ -354,8 +354,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_USUBO_CARRY) {
   EXPECT_EQ(Known.One, APInt(8, 0x30));
 
   auto ZeroBorrow = DAG->getConstant(0x0, Loc, IntVT);
-  auto OpZeroBorrow = DAG->getNode(
-      ISD::USUBO_CARRY, Loc, IntVT, N0, N1, ZeroBorrow);
+  auto OpZeroBorrow =
+      DAG->getNode(ISD::USUBO_CARRY, Loc, IntVT, N0, N1, ZeroBorrow);
   // N0 = 01011010
   // N1 = 0010?000
   // B  =        0
@@ -367,8 +367,8 @@ TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_USUBO_CARRY) {
   EXPECT_EQ(Known.One, APInt(8, 0x32));
 
   auto OneBorrow = DAG->getConstant(0x1, Loc, IntVT);
-  auto OpOneBorrow = DAG->getNode(
-      ISD::USUBO_CARRY, Loc, IntVT, N0, N1, OneBorrow);
+  auto OpOneBorrow =
+      DAG->getNode(ISD::USUBO_CARRY, Loc, IntVT, N0, N1, OneBorrow);
   // N0 = 01011010
   // N1 = 0010?000
   // B  =        1

@christiankissig
Copy link
Contributor Author

Re-issuing PR after updating code formatting and rebasing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well llvm:support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants