Skip to content

Commit 7bc2cd6

Browse files
author
Yeting Kuo
committed
[VP][DAGCombiner] Introduce generalized pattern match for vp sdnodes.
The patch tries to solve duplicated combine work for vp sdnodes. The idea is to introduce MatchConext that verifies specific patterns and generate specific node infromation. There is two MatchConext in DAGCombiner. EmptyMatcher is for normal nodes and VPMatcher is for vp nodes. The idea of this patch is come form Simon Moll's proposal [0]. I only fixed some minor issues and added few new features in this patch. [0]: sx-aurora-dev/llvm-project@c38a144 Reviewed By: craig.topper Differential Revision: https://reviews.llvm.org/D141891
1 parent d768b97 commit 7bc2cd6

File tree

5 files changed

+284
-43
lines changed

5 files changed

+284
-43
lines changed

llvm/include/llvm/CodeGen/ISDOpcodes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,12 @@ std::optional<unsigned> getVPMaskIdx(unsigned Opcode);
13461346
/// The operand position of the explicit vector length parameter.
13471347
std::optional<unsigned> getVPExplicitVectorLengthIdx(unsigned Opcode);
13481348

1349+
/// Translate this VP Opcode to its corresponding non-VP Opcode.
1350+
std::optional<unsigned> getBaseOpcodeForVP(unsigned Opcode, bool hasFPExcept);
1351+
1352+
/// Translate this non-VP Opcode to its corresponding VP Opcode.
1353+
unsigned getVPForBaseOpcode(unsigned Opcode);
1354+
13491355
//===--------------------------------------------------------------------===//
13501356
/// MemIndexedMode enum - This enum defines the load / store indexed
13511357
/// addressing modes.

llvm/include/llvm/IR/VPIntrinsics.def

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
#define VP_PROPERTY_CONSTRAINEDFP(HASROUND, HASEXCEPT, INTRINID)
107107
#endif
108108

109+
// The intrinsic and/or SDNode has the same function as this ISD Opcode.
110+
// \p SDOPC The opcode of the instruction with the same function.
111+
#ifndef VP_PROPERTY_FUNCTIONAL_SDOPC
112+
#define VP_PROPERTY_FUNCTIONAL_SDOPC(SDOPC)
113+
#endif
114+
109115
// Map this VP intrinsic to its canonical functional intrinsic.
110116
// \p INTRIN The non-VP intrinsics with the same function.
111117
#ifndef VP_PROPERTY_FUNCTIONAL_INTRINSIC
@@ -265,27 +271,28 @@ END_REGISTER_VP(vp_fshr, VP_FSHR)
265271
#error \
266272
"The internal helper macro HELPER_REGISTER_BINARY_FP_VP is already defined!"
267273
#endif
268-
#define HELPER_REGISTER_BINARY_FP_VP(OPSUFFIX, VPSD, IROPC) \
274+
#define HELPER_REGISTER_BINARY_FP_VP(OPSUFFIX, VPSD, IROPC, SDOPC) \
269275
BEGIN_REGISTER_VP(vp_##OPSUFFIX, 2, 3, VPSD, -1) \
270276
VP_PROPERTY_FUNCTIONAL_OPC(IROPC) \
271277
VP_PROPERTY_CONSTRAINEDFP(1, 1, experimental_constrained_##OPSUFFIX) \
278+
VP_PROPERTY_FUNCTIONAL_SDOPC(SDOPC) \
272279
VP_PROPERTY_BINARYOP \
273280
END_REGISTER_VP(vp_##OPSUFFIX, VPSD)
274281

275282
// llvm.vp.fadd(x,y,mask,vlen)
276-
HELPER_REGISTER_BINARY_FP_VP(fadd, VP_FADD, FAdd)
283+
HELPER_REGISTER_BINARY_FP_VP(fadd, VP_FADD, FAdd, FADD)
277284

278285
// llvm.vp.fsub(x,y,mask,vlen)
279-
HELPER_REGISTER_BINARY_FP_VP(fsub, VP_FSUB, FSub)
286+
HELPER_REGISTER_BINARY_FP_VP(fsub, VP_FSUB, FSub, FSUB)
280287

281288
// llvm.vp.fmul(x,y,mask,vlen)
282-
HELPER_REGISTER_BINARY_FP_VP(fmul, VP_FMUL, FMul)
289+
HELPER_REGISTER_BINARY_FP_VP(fmul, VP_FMUL, FMul, FMUL)
283290

284291
// llvm.vp.fdiv(x,y,mask,vlen)
285-
HELPER_REGISTER_BINARY_FP_VP(fdiv, VP_FDIV, FDiv)
292+
HELPER_REGISTER_BINARY_FP_VP(fdiv, VP_FDIV, FDiv, FDIV)
286293

287294
// llvm.vp.frem(x,y,mask,vlen)
288-
HELPER_REGISTER_BINARY_FP_VP(frem, VP_FREM, FRem)
295+
HELPER_REGISTER_BINARY_FP_VP(frem, VP_FREM, FRem, FREM)
289296

290297
#undef HELPER_REGISTER_BINARY_FP_VP
291298

@@ -305,6 +312,7 @@ END_REGISTER_VP(vp_sqrt, VP_SQRT)
305312
// llvm.vp.fma(x,y,z,mask,vlen)
306313
BEGIN_REGISTER_VP(vp_fma, 3, 4, VP_FMA, -1)
307314
VP_PROPERTY_CONSTRAINEDFP(1, 1, experimental_constrained_fma)
315+
VP_PROPERTY_FUNCTIONAL_SDOPC(FMA)
308316
END_REGISTER_VP(vp_fma, VP_FMA)
309317

310318
// llvm.vp.fmuladd(x,y,z,mask,vlen)
@@ -630,5 +638,6 @@ END_REGISTER_VP(experimental_vp_splice, EXPERIMENTAL_VP_SPLICE)
630638
#undef VP_PROPERTY_CONSTRAINEDFP
631639
#undef VP_PROPERTY_FUNCTIONAL_INTRINSIC
632640
#undef VP_PROPERTY_FUNCTIONAL_OPC
641+
#undef VP_PROPERTY_FUNCTIONAL_SDOPC
633642
#undef VP_PROPERTY_MEMOP
634643
#undef VP_PROPERTY_REDUCTION

0 commit comments

Comments
 (0)