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

[SDAG] Apply or-disjoint in SelectionDAG::isBaseWithConstantOffset #88493

Merged
merged 2 commits into from
Apr 15, 2024

Conversation

fengfeng09
Copy link
Contributor

Or-disjoint application.

Copy link

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 @ followed by their GitHub username.

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.

@llvmbot llvmbot added the llvm:SelectionDAG SelectionDAGISel as well label Apr 12, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Apr 12, 2024

@llvm/pr-subscribers-llvm-selectiondag

Author: fengfeng (fengfeng09)

Changes

Or-disjoint application.


Full diff: https://github.com/llvm/llvm-project/pull/88493.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+3)
  • (added) llvm/test/CodeGen/AVR/base-with-add-like-constant-offset.ll (+20)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 1dd0fa49a460f8..67feb47fef076f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -5191,6 +5191,9 @@ bool SelectionDAG::isADDLike(SDValue Op) const {
 }
 
 bool SelectionDAG::isBaseWithConstantOffset(SDValue Op) const {
+  if (isADDLike(Op) && isa<ConstantSDNode>(Op.getOperand(1)))
+    return true;
+
   if ((Op.getOpcode() != ISD::ADD && Op.getOpcode() != ISD::OR) ||
       !isa<ConstantSDNode>(Op.getOperand(1)))
     return false;
diff --git a/llvm/test/CodeGen/AVR/base-with-add-like-constant-offset.ll b/llvm/test/CodeGen/AVR/base-with-add-like-constant-offset.ll
new file mode 100644
index 00000000000000..6077f71b5efe06
--- /dev/null
+++ b/llvm/test/CodeGen/AVR/base-with-add-like-constant-offset.ll
@@ -0,0 +1,20 @@
+; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+; RUN: llc -mtriple=avr %s -start-before=avr-isel -o - -stop-after=avr-isel | FileCheck %s
+
+define void @test(i16 %x, ptr addrspace(1) %o) {
+  ; CHECK-LABEL: name: test
+  ; CHECK: bb.0 (%ir-block.0):
+  ; CHECK-NEXT:   liveins: $r25r24, $r23r22
+  ; CHECK-NEXT: {{  $}}
+  ; CHECK-NEXT:   [[COPY:%[0-9]+]]:dregs = COPY $r23r22
+  ; CHECK-NEXT:   [[COPY1:%[0-9]+]]:dregs = COPY $r25r24
+  ; CHECK-NEXT:   [[COPY2:%[0-9]+]]:ptrdispregs = COPY [[COPY]]
+  ; CHECK-NEXT:   STDWPtrQRr [[COPY2]], 10, [[COPY1]] :: (store (s16) into %ir.addr, align 1, addrspace 1)
+  ; CHECK-NEXT:   RET implicit $r1
+  %int = ptrtoint ptr addrspace(1) %o to i16
+  %or = or disjoint i16 %int, 10
+  %addr = inttoptr i16 %or to ptr addrspace(1)
+  store i16 %x, ptr addrspace(1) %addr
+  ret void
+}
+

@@ -5191,6 +5191,9 @@ bool SelectionDAG::isADDLike(SDValue Op) const {
}

bool SelectionDAG::isBaseWithConstantOffset(SDValue Op) const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not just simplify this function to:

bool SelectionDAG::isBaseWithConstantOffset(SDValue Op) const {
  return (Op.getOpcode() == ISD::ADD || isADDLike(Op)) &&
         isa<ConstantSDNode>(Op.getOperand(1));
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion.

@fengfeng09 fengfeng09 force-pushed the base-with-add-like-constant-offset branch from fa99586 to f20ac0a Compare April 12, 2024 15:19
@fengfeng09 fengfeng09 requested a review from RKSimon April 12, 2024 15:20
Copy link
Collaborator

@RKSimon RKSimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@arsenm arsenm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title should be improved, it is missing any context

return false;

return true;
return (Op.getOpcode() == ISD::ADD || isADDLike(Op)) &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can call computeKnownBits on both operands an OR that doesn't have a constant right hand side. Is there better way to do that with the cheap constant right hand side check first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

@fengfeng09 fengfeng09 force-pushed the base-with-add-like-constant-offset branch from f20ac0a to 88d114e Compare April 13, 2024 01:56
@fengfeng09 fengfeng09 changed the title Base with add like constant offset Apply or-disjoint in SelectionDAG::isBaseWithConstantOffset Apr 13, 2024
return false;

return true;
return isa<ConstantSDNode>(Op.getOperand(1)) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash if the node doesn't have a second operand.

@fengfeng09 fengfeng09 force-pushed the base-with-add-like-constant-offset branch 2 times, most recently from b1fafcc to 51c05ea Compare April 13, 2024 09:11
@fengfeng09 fengfeng09 requested a review from nikic April 13, 2024 09:21
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

@nikic nikic changed the title Apply or-disjoint in SelectionDAG::isBaseWithConstantOffset [SDAG] Apply or-disjoint in SelectionDAG::isBaseWithConstantOffset Apr 13, 2024
Signed-off-by: feng.feng <feng.feng@iluvatar.com>
If the addr base of a Load/Store Inst is an Or-disjoint with a constant,
it could be selected to an MI with constans offset if the target have.

Signed-off-by: feng.feng <feng.feng@iluvatar.com>
@fengfeng09 fengfeng09 force-pushed the base-with-add-like-constant-offset branch from 51c05ea to 8e03689 Compare April 15, 2024 04:29
@fengfeng09
Copy link
Contributor Author

I have no write access to the repo,could someone help me to merge this PR?

@nikic nikic merged commit 7177dc2 into llvm:main Apr 15, 2024
3 of 4 checks passed
Copy link

@fengfeng09 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!

@fengfeng09 fengfeng09 deleted the base-with-add-like-constant-offset branch April 15, 2024 05:18
bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants