Skip to content

[SelectionDAG] Propagate Disjoint flag. #88370

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

Merged
merged 2 commits into from
Apr 15, 2024
Merged

[SelectionDAG] Propagate Disjoint flag. #88370

merged 2 commits into from
Apr 15, 2024

Conversation

fengfeng09
Copy link
Contributor

No description provided.

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 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 11, 2024

@llvm/pr-subscribers-backend-x86

@llvm/pr-subscribers-llvm-selectiondag

Author: fengfeng (fengfeng09)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+2)
  • (modified) llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp (+2)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 8fe074666a3dc9..59ef66fba73164 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9530,6 +9530,8 @@ static SDValue combineShiftOfShiftedLogic(SDNode *Shift, SelectionDAG &DAG) {
   SDValue ShiftSumC = DAG.getConstant(*C0Val + C1Val, DL, ShiftAmtVT);
   SDValue NewShift1 = DAG.getNode(ShiftOpcode, DL, VT, X, ShiftSumC);
   SDValue NewShift2 = DAG.getNode(ShiftOpcode, DL, VT, Y, C1);
+  // Propogate flags.
+  SelectionDAG::FlagInserter FlagsInserter(DAG, LogicOp->getFlags());
   return DAG.getNode(LogicOpcode, DL, VT, NewShift1, NewShift2);
 }
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 409d66adfd67d1..dd5c3d741aa7dc 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -544,6 +544,8 @@ bool TargetLowering::ShrinkDemandedConstant(SDValue Op,
     if (!C.isSubsetOf(DemandedBits)) {
       EVT VT = Op.getValueType();
       SDValue NewC = TLO.DAG.getConstant(DemandedBits & C, DL, VT);
+      // Propogate flags.
+      SelectionDAG::FlagInserter FlagsInserter(TLO.DAG, Op->getFlags());
       SDValue NewOp = TLO.DAG.getNode(Opcode, DL, VT, Op.getOperand(0), NewC);
       return TLO.CombineTo(Op, NewOp);
     }

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.

Tests?

@RKSimon RKSimon requested review from topperc and goldsteinn April 11, 2024 10:37
@fengfeng09 fengfeng09 requested a review from RKSimon April 11, 2024 10:40
Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

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

Please add some tests for these changes.

@goldsteinn
Copy link
Contributor

Tests?

Just a note, the general practice is to "pre commit" your tests. What that means is your PR should have two commits.
Commit 1) Tests w/o your implementation
Commit 2) Your implementation w/ updated tests (using llvm/utils/update_llc_test_checks.py in this case).

That way we can see the diff.

@fengfeng09
Copy link
Contributor Author

Thanks all, updated.

@@ -9530,6 +9530,8 @@ static SDValue combineShiftOfShiftedLogic(SDNode *Shift, SelectionDAG &DAG) {
SDValue ShiftSumC = DAG.getConstant(*C0Val + C1Val, DL, ShiftAmtVT);
SDValue NewShift1 = DAG.getNode(ShiftOpcode, DL, VT, X, ShiftSumC);
SDValue NewShift2 = DAG.getNode(ShiftOpcode, DL, VT, Y, C1);
// Propogate flags.
Copy link
Contributor

Choose a reason for hiding this comment

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

@fengfeng09 fengfeng09 force-pushed the main branch 2 times, most recently from 6efab5d to c73c2d3 Compare April 13, 2024 02:46
@jayfoad
Copy link
Contributor

jayfoad commented Apr 13, 2024

Typo in subject "propagate"

@fengfeng09 fengfeng09 changed the title [SelectionDAG] Propogate Disjoint flag. [SelectionDAG] Propagate Disjoint flag. Apr 13, 2024
@fengfeng09 fengfeng09 force-pushed the main branch 2 times, most recently from c8b6a2a to 48f5c9e Compare April 13, 2024 09:19
Copy link
Member

@dtcxzyw dtcxzyw left a comment

Choose a reason for hiding this comment

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

LGTM. Nice catch!

@@ -9530,6 +9530,7 @@ static SDValue combineShiftOfShiftedLogic(SDNode *Shift, SelectionDAG &DAG) {
SDValue ShiftSumC = DAG.getConstant(*C0Val + C1Val, DL, ShiftAmtVT);
SDValue NewShift1 = DAG.getNode(ShiftOpcode, DL, VT, X, ShiftSumC);
SDValue NewShift2 = DAG.getNode(ShiftOpcode, DL, VT, Y, C1);
SelectionDAG::FlagInserter FlagsInserter(DAG, LogicOp->getFlags());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need to use FlagInserter? Can't we pass the flags to the last argument of getNode?

Signed-off-by: feng.feng <feng.feng@iluvatar.com>
Signed-off-by: feng.feng <feng.feng@iluvatar.com>
@fengfeng09
Copy link
Contributor Author

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

@arsenm arsenm merged commit 36230f9 into llvm:main Apr 15, 2024
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!

bazuzi pushed a commit to bazuzi/llvm-project that referenced this pull request Apr 15, 2024
Signed-off-by: feng.feng <feng.feng@iluvatar.com>
aniplcc pushed a commit to aniplcc/llvm-project that referenced this pull request Apr 15, 2024
Signed-off-by: feng.feng <feng.feng@iluvatar.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 llvm:SelectionDAG SelectionDAGISel as well
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants