Skip to content

[LoongArch] Improve pattern matching for AddLike predicate #82767

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
Feb 26, 2024

Conversation

heiher
Copy link
Member

@heiher heiher commented Feb 23, 2024

This commit updates the pattern matching logic for the AddLike predicate in LoongArchInstrInfo.td to use the isBaseWithConstantOffset function provided by CurDAG. This optimization aims to improve the efficiency of pattern matching by identifying cases where the operation can be represented as a base address plus a constant offset, which can lead to more efficient code generation.

`SelectionDAGISel::isOrEquivalentToAdd` can only test operands that are
directly based on the stack frame. The improvement in this commit is to
add a call to `SelectionDAG::haveNoCommonBitsSet` for testing, which
helps optimize the code generation for `load (or base, imm)`.
@llvmbot llvmbot added backend:loongarch llvm:SelectionDAG SelectionDAGISel as well labels Feb 23, 2024
@heiher heiher requested a review from asb February 23, 2024 13:45
@llvmbot
Copy link
Member

llvmbot commented Feb 23, 2024

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-loongarch

Author: hev (heiher)

Changes

SelectionDAGISel::isOrEquivalentToAdd can only test operands that are directly based on the stack frame. The improvement in this commit is to add a call to SelectionDAG::haveNoCommonBitsSet for testing, which helps optimize the code generation for load (or base, imm).


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (+1-1)
  • (modified) llvm/test/CodeGen/LoongArch/intrinsic-memcpy.ll (+1-2)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 9b5ab4267b80e9..0cf9a02af35c49 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -4214,7 +4214,7 @@ bool SelectionDAGISel::isOrEquivalentToAdd(const SDNode *N) const {
     // the alignment, then this or is really an add.
     return (Off >= 0) && (((A.value() - 1) & Off) == unsigned(Off));
   }
-  return false;
+  return CurDAG->haveNoCommonBitsSet(N->getOperand(0), N->getOperand(1));
 }
 
 void SelectionDAGISel::CannotYetSelect(SDNode *N) {
diff --git a/llvm/test/CodeGen/LoongArch/intrinsic-memcpy.ll b/llvm/test/CodeGen/LoongArch/intrinsic-memcpy.ll
index 09453004dcef74..ff845cb1f3dbd9 100644
--- a/llvm/test/CodeGen/LoongArch/intrinsic-memcpy.ll
+++ b/llvm/test/CodeGen/LoongArch/intrinsic-memcpy.ll
@@ -22,8 +22,7 @@ define void @box(ptr noalias nocapture noundef writeonly sret(%Box) align 16 der
 ; CHECK-NEXT:    st.d $a1, $a0, 24
 ; CHECK-NEXT:    ld.d $a1, $a3, 16
 ; CHECK-NEXT:    st.d $a1, $a0, 16
-; CHECK-NEXT:    ori $a1, $a3, 8
-; CHECK-NEXT:    ld.d $a1, $a1, 0
+; CHECK-NEXT:    ld.d $a1, $a3, 8
 ; CHECK-NEXT:    st.d $a1, $a0, 8
 ; CHECK-NEXT:    addi.d $sp, $sp, 96
 ; CHECK-NEXT:    ret

@heiher heiher requested a review from SixWeining February 23, 2024 13:46
This commit updates the pattern matching logic for the `AddLike` predicate in
`LoongArchInstrInfo.td` to use the `isBaseWithConstantOffset` function provided
by `CurDAG`. This optimization aims to improve the effciency of pattern matching
by identifying cases where the operation can be represented as a base address
plus a constant offset, which can lead to more efficient code generation.
@heiher heiher changed the title [SelectionDAG] Improve isOrEquivalentToAdd [LoongArch] Improve pattern matching for AddLike predicate Feb 24, 2024
Copy link
Collaborator

@topperc topperc left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants