[PATCH] D144075: [DAGCombiner] Teach MatchContextClass classes to use TargetLowering::isOperationLegalOrCustom().
Yeting Kuo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 15 00:24:58 PST 2023
fakepaper56 created this revision.
fakepaper56 added reviewers: simoll, craig.topper, frasercrmck, RKSimon, spatel, reames.
Herald added subscribers: StephenFan, ecnelises, steven.zhang, hiraditya.
Herald added a project: All.
fakepaper56 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Some of TargetLowering functions needed opcodes are often used in DAGCombiner.
The patch make those MatchContextClass classes have TargetLowering members and
pass specific opcodes for those TargetLowering functions.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144075
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -854,9 +854,11 @@
class EmptyMatchContext {
SelectionDAG &DAG;
+ const TargetLowering &TLI;
public:
- EmptyMatchContext(SelectionDAG &DAG, SDNode *Root) : DAG(DAG) {}
+ EmptyMatchContext(SelectionDAG &DAG, const TargetLowering &TLI, SDNode *Root)
+ : DAG(DAG), TLI(TLI) {}
bool match(SDValue OpN, unsigned Opcode) const {
return Opcode == OpN->getOpcode();
@@ -866,16 +868,22 @@
template <typename... ArgT> SDValue getNode(ArgT &&...Args) {
return DAG.getNode(std::forward<ArgT>(Args)...);
}
+
+ bool isOperationLegalOrCustom(unsigned Op, EVT VT,
+ bool LegalOnly = false) const {
+ return TLI.isOperationLegalOrCustom(Op, VT, LegalOnly);
+ }
};
class VPMatchContext {
SelectionDAG &DAG;
+ const TargetLowering &TLI;
SDValue RootMaskOp;
SDValue RootVectorLenOp;
public:
- VPMatchContext(SelectionDAG &DAG, SDNode *Root)
- : DAG(DAG), RootMaskOp(), RootVectorLenOp() {
+ VPMatchContext(SelectionDAG &DAG, const TargetLowering &TLI, SDNode *Root)
+ : DAG(DAG), TLI(TLI), RootMaskOp(), RootVectorLenOp() {
assert(Root->isVPOpcode());
if (auto RootMaskPos = ISD::getVPMaskIdx(Root->getOpcode()))
RootMaskOp = Root->getOperand(*RootMaskPos);
@@ -968,6 +976,12 @@
return DAG.getNode(VPOpcode, DL, VT,
{N1, N2, N3, RootMaskOp, RootVectorLenOp}, Flags);
}
+
+ bool isOperationLegalOrCustom(unsigned Op, EVT VT,
+ bool LegalOnly = false) const {
+ unsigned VPOp = ISD::getVPForBaseOpcode(Op);
+ return TLI.isOperationLegalOrCustom(VPOp, VT, LegalOnly);
+ }
};
} // end anonymous namespace
@@ -14870,7 +14884,7 @@
SDValue N1 = N->getOperand(1);
EVT VT = N->getValueType(0);
SDLoc SL(N);
- MatchContextClass matcher(DAG, N);
+ MatchContextClass matcher(DAG, TLI, N);
const TargetOptions &Options = DAG.getTarget().Options;
bool UseVP = std::is_same_v<MatchContextClass, VPMatchContext>;
@@ -14881,9 +14895,9 @@
bool HasFMAD = !UseVP && (LegalOperations && TLI.isFMADLegal(DAG, N));
// Floating-point multiply-add without intermediate rounding.
- unsigned FMAOpc = UseVP ? ISD::VP_FMA : ISD::FMA;
- bool HasFMA = TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT) &&
- (!LegalOperations || TLI.isOperationLegalOrCustom(FMAOpc, VT));
+ bool HasFMA =
+ TLI.isFMAFasterThanFMulAndFAdd(DAG.getMachineFunction(), VT) &&
+ (!LegalOperations || matcher.isOperationLegalOrCustom(ISD::FMA, VT));
// No valid opcode, do not combine.
if (!HasFMAD && !HasFMA)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144075.497578.patch
Type: text/x-patch
Size: 2828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230215/579aabb5/attachment.bin>
More information about the llvm-commits
mailing list