Skip to content

Conversation

@abhishek-kaushik22
Copy link
Contributor

@abhishek-kaushik22 abhishek-kaushik22 commented Jun 24, 2025

Add SDPatternMatch matcher and unit test coverage for ISD::LOAD opcode.
This only matches the loaded value i.e. ResNo 0 and not the output chain.
e.g.

m_Load(m_Value(), m_Value(), m_Value())

The first value is the input chain, the second is the base pointer, and the last value is the offset.

@RKSimon RKSimon requested a review from mshockwave June 24, 2025 10:12
template <typename T0_P, typename T1_P, typename T2_P>
inline TernaryOpc_match<T0_P, T1_P, T2_P>
m_Load(const T0_P &Ch, const T1_P &Ptr, const T2_P &Offset) {
return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::LOAD, Ch, Ptr, Offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this match for both Load.getValue(0) (the loaded value) and Load.getValue(1) (the out chain)? Or should we have a template/run arg to match?

Copy link
Member

Choose a reason for hiding this comment

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

I think having a way to distinguish which (SDValue) result to match would indeed be helpful. For instance, to match a SDNode with optional input chain, we can't tell if operand 0 is a chain or not, other than something like m_AllOf(m_SpecificVT(MVT::Other), <matcher for operand 0>) or using a matching class that uses EffectiveOperand, which skips over chains and glues (but not every matching classes use it).

Not necessary for this patch, but we might want a more general solution, for instance m_Result<0>(m_Load(...)) for matching the first result of a load.

Copy link
Collaborator

Choose a reason for hiding this comment

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

OK - for now let's just match against ResNo == 0 as that's what most people will expect from m_Load

Copy link
Collaborator

Choose a reason for hiding this comment

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

When #145775 lands this will need to be:

return m_Result<0>(TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::LOAD, Ch, Ptr, Offset));

@abhishek-kaushik22
Copy link
Contributor Author

The failed test looks unrelated to this LLVM :: CodeGen/AMDGPU/pal-metadata-3.0-callable-dvgpr.ll

@RKSimon @mshockwave are there any changes required here?

Copy link
Member

@mshockwave mshockwave left a comment

Choose a reason for hiding this comment

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

LGTM
Please add a patch description though

template <typename T0_P, typename T1_P, typename T2_P>
inline TernaryOpc_match<T0_P, T1_P, T2_P>
m_Load(const T0_P &Ch, const T1_P &Ptr, const T2_P &Offset) {
return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::LOAD, Ch, Ptr, Offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

When #145775 lands this will need to be:

return m_Result<0>(TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::LOAD, Ch, Ptr, Offset));

abhishek-kaushik22 pushed a commit that referenced this pull request Jun 26, 2025
…#145775)

`m_Result<N>` matches a SDValue that is the N-th result of the defining
SDNode. This is useful for creating a more fine-grained matching on
SDNode with multiple results.

-----
Inspired by #145481
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 - cheers

@abhishek-kaushik22 abhishek-kaushik22 merged commit abf8e25 into llvm:main Jun 26, 2025
6 of 7 checks passed
@abhishek-kaushik22 abhishek-kaushik22 deleted the m_load branch June 26, 2025 17:33
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
…llvm#145775)

`m_Result<N>` matches a SDValue that is the N-th result of the defining
SDNode. This is useful for creating a more fine-grained matching on
SDNode with multiple results.

-----
Inspired by llvm#145481
anthonyhatran pushed a commit to anthonyhatran/llvm-project that referenced this pull request Jun 26, 2025
Add SDPatternMatch matcher and unit test coverage for `ISD::LOAD`
opcode.
This only matches the loaded value i.e. ResNo 0 and not the output
chain.
e.g.
```
m_Load(m_Value(), m_Value(), m_Value())
```

The first value is the input chain, the second is the base pointer, and
the last value is the offset.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants