[DAG] Improved handling of ISD::ROTL and ISD::ROTR in isKnownToBeAPowerOfTwo - #182744
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-llvm-selectiondag Author: Mir Immad (mirimmad) ChangesFixes #181642 Full diff: https://github.com/llvm/llvm-project/pull/182744.diff 2 Files Affected:
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 581553d41cb6d..971c5f5674ecb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4733,8 +4733,7 @@ bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val,
case ISD::ROTL:
case ISD::ROTR:
- return isKnownToBeAPowerOfTwo(Val.getOperand(0), /*OrZero=*/false,
- Depth + 1);
+ return isKnownToBeAPowerOfTwo(Val.getOperand(0), false, Depth + 1);
case ISD::SMIN:
case ISD::SMAX:
diff --git a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
index b2b8dfb0c21fc..33a3540f6b562 100644
--- a/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
+++ b/llvm/unittests/Target/AArch64/AArch64SelectionDAGTest.cpp
@@ -1119,6 +1119,55 @@ TEST_F(AArch64SelectionDAGTest,
EXPECT_EQ(SplatIdx, 0);
}
+TEST_F(AArch64SelectionDAGTest, KnownToBeAPowerOfTwo_ROTL) {
+ SDLoc Loc;
+ auto IntVT = EVT::getIntegerVT(Context, 32);
+
+ // Power-of-two values
+ auto Pow2_4 = DAG->getConstant(4, Loc, IntVT);
+ auto Pow2_8 = DAG->getConstant(8, Loc, IntVT);
+
+ // Non-power-of-two values
+ auto NonPow2_5 = DAG->getConstant(5, Loc, IntVT);
+ auto NonPow2_0 = DAG->getConstant(0, Loc, IntVT);
+
+ auto RotAmount = DAG->getConstant(3, Loc, IntVT);
+
+ auto RotlPow2_4 = DAG->getNode(ISD::ROTL, Loc, IntVT, Pow2_4, RotAmount);
+ auto RotlPow2_8 = DAG->getNode(ISD::ROTL, Loc, IntVT, Pow2_8, RotAmount);
+ auto RotlNonPow2_5 =
+ DAG->getNode(ISD::ROTL, Loc, IntVT, NonPow2_5, RotAmount);
+ auto RotlZero = DAG->getNode(ISD::ROTL, Loc, IntVT, NonPow2_0, RotAmount);
+
+ EXPECT_TRUE(DAG->isKnownToBeAPowerOfTwo(RotlPow2_4));
+ EXPECT_TRUE(DAG->isKnownToBeAPowerOfTwo(RotlPow2_8));
+
+ EXPECT_FALSE(DAG->isKnownToBeAPowerOfTwo(RotlNonPow2_5));
+
+ EXPECT_FALSE(DAG->isKnownToBeAPowerOfTwo(RotlZero));
+ EXPECT_TRUE(DAG->isKnownToBeAPowerOfTwo(RotlZero, /*OrZero=*/true));
+}
+
+TEST_F(AArch64SelectionDAGTest, KnownToBeAPowerOfTwo_ROTR) {
+ SDLoc Loc;
+ auto IntVT = EVT::getIntegerVT(Context, 32);
+
+ auto Pow2_16 = DAG->getConstant(16, Loc, IntVT);
+ auto NonPow2_6 = DAG->getConstant(6, Loc, IntVT);
+ auto Zero = DAG->getConstant(0, Loc, IntVT);
+
+ auto RotAmount = DAG->getConstant(5, Loc, IntVT);
+
+ auto RotrPow2 = DAG->getNode(ISD::ROTR, Loc, IntVT, Pow2_16, RotAmount);
+ auto RotrNonPow2 = DAG->getNode(ISD::ROTR, Loc, IntVT, NonPow2_6, RotAmount);
+ auto RotrZero = DAG->getNode(ISD::ROTR, Loc, IntVT, Zero, RotAmount);
+
+ EXPECT_TRUE(DAG->isKnownToBeAPowerOfTwo(RotrPow2));
+ EXPECT_FALSE(DAG->isKnownToBeAPowerOfTwo(RotrNonPow2));
+ EXPECT_FALSE(DAG->isKnownToBeAPowerOfTwo(RotrZero));
+ EXPECT_TRUE(DAG->isKnownToBeAPowerOfTwo(RotrZero, /*OrZero=*/true));
+}
+
TEST_F(AArch64SelectionDAGTest, getRepeatedSequence_Patterns) {
TargetLowering TL(*TM, *STI);
|
|
@RKSimon Made the changes, thanks. |
|
@arsenm There are already tests for |
|
✅ With the latest revision this PR passed the undef deprecator. |
| @@ -11,6 +11,8 @@ declare i32 @llvm.smin.i32(i32, i32) | |||
| declare i32 @llvm.smax.i32(i32, i32) | |||
| declare i32 @llvm.fshl.i32(i32, i32, i32) | |||
| declare i32 @llvm.fshr.i32(i32, i32, i32) | |||
| declare <2 x i32> @llvm.fshl.v2i32(<2 x i32>, <2 x i32>, <2 x i32>) | |||
| declare <2 x i32> @llvm.fshr.v2i32(<2 x i32>, <2 x i32>, <2 x i32>) | |||
There was a problem hiding this comment.
don't bother adding these - we don't need to declare anymore
| @@ -889,3 +891,32 @@ define i1 @pow2_and_i128(i128 %num, i128 %shift) { | |||
| %bool = icmp eq i128 %bit, 0 | |||
| ret i1 %bool | |||
| } | |||
|
|
|||
| define <2 x i32> @pow2_rotl_vec() { | |||
There was a problem hiding this comment.
Use the update_llc_test_checks script
…erOfTwo' and associated tests
Use zeroinitializer instead of undef.
RKSimon
left a comment
There was a problem hiding this comment.
Please fix the bad merge (test files?)
5b0ac03 to
97e2eb2
Compare
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
|
@mirimmad Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Fixes #181642