[llvm] abf8e25 - [DAG] Add `SDPatternMatch::m_Load` (#145481)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 26 10:33:34 PDT 2025
Author: Abhishek Kaushik
Date: 2025-06-26T23:03:31+05:30
New Revision: abf8e25ac7644dd035361383ec4f74e0456c1b3e
URL: https://github.com/llvm/llvm-project/commit/abf8e25ac7644dd035361383ec4f74e0456c1b3e
DIFF: https://github.com/llvm/llvm-project/commit/abf8e25ac7644dd035361383ec4f74e0456c1b3e.diff
LOG: [DAG] Add `SDPatternMatch::m_Load` (#145481)
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.
Added:
Modified:
llvm/include/llvm/CodeGen/SDPatternMatch.h
llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/SDPatternMatch.h b/llvm/include/llvm/CodeGen/SDPatternMatch.h
index 9228ccd433b27..83187b4a0241c 100644
--- a/llvm/include/llvm/CodeGen/SDPatternMatch.h
+++ b/llvm/include/llvm/CodeGen/SDPatternMatch.h
@@ -530,6 +530,13 @@ m_VSelect(const T0_P &Cond, const T1_P &T, const T2_P &F) {
return TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::VSELECT, Cond, T, F);
}
+template <typename T0_P, typename T1_P, typename T2_P>
+inline Result_match<0, TernaryOpc_match<T0_P, T1_P, T2_P>>
+m_Load(const T0_P &Ch, const T1_P &Ptr, const T2_P &Offset) {
+ return m_Result<0>(
+ TernaryOpc_match<T0_P, T1_P, T2_P>(ISD::LOAD, Ch, Ptr, Offset));
+}
+
template <typename T0_P, typename T1_P, typename T2_P>
inline TernaryOpc_match<T0_P, T1_P, T2_P>
m_InsertElt(const T0_P &Vec, const T1_P &Val, const T2_P &Idx) {
diff --git a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
index e33fc30a7affe..a60b87c80a02c 100644
--- a/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
+++ b/llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp
@@ -178,6 +178,12 @@ TEST_F(SelectionDAGPatternMatchTest, matchTernaryOp) {
SDValue ExtractELT =
DAG->getNode(ISD::EXTRACT_VECTOR_ELT, DL, Int32VT, V1, Op3);
+ SDValue Ch = DAG->getEntryNode();
+ SDValue BasePtr = DAG->getRegister(1, MVT::i64);
+ SDValue Offset = DAG->getUNDEF(MVT::i64);
+ MachinePointerInfo PtrInfo;
+ SDValue Load = DAG->getLoad(MVT::i32, DL, Ch, BasePtr, PtrInfo);
+
using namespace SDPatternMatch;
ISD::CondCode CC;
EXPECT_TRUE(sd_match(ICMP_UGT, m_SetCC(m_Value(), m_Value(),
@@ -230,6 +236,13 @@ TEST_F(SelectionDAGPatternMatchTest, matchTernaryOp) {
EXPECT_FALSE(sd_match(
InsertSubvector,
m_InsertSubvector(m_Specific(V2), m_Specific(V3), m_SpecificInt(3))));
+
+ EXPECT_TRUE(sd_match(
+ Load, m_Load(m_Specific(Ch), m_Specific(BasePtr), m_Specific(Offset))));
+
+ EXPECT_FALSE(
+ sd_match(Load.getValue(1), m_Load(m_Specific(Ch), m_Specific(BasePtr),
+ m_Specific(Offset))));
}
TEST_F(SelectionDAGPatternMatchTest, matchBinaryOp) {
More information about the llvm-commits
mailing list