[llvm] a96cbeb - [DAGCombiner] Teach MatchContextClass classes to use TargetLowering::isOperationLegalOrCustom().
Yeting Kuo via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 16 23:58:54 PST 2023
Author: Yeting Kuo
Date: 2023-02-17T15:58:47+08:00
New Revision: a96cbeb450626c7643f2c00d6dddfd142d89eb74
URL: https://github.com/llvm/llvm-project/commit/a96cbeb450626c7643f2c00d6dddfd142d89eb74
DIFF: https://github.com/llvm/llvm-project/commit/a96cbeb450626c7643f2c00d6dddfd142d89eb74.diff
LOG: [DAGCombiner] Teach MatchContextClass classes to use TargetLowering::isOperationLegalOrCustom().
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.
Reviewed By: RKSimon
Differential Revision: https://reviews.llvm.org/D144075
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 2332b5b95cc13..b436e0ddec73e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -852,9 +852,11 @@ class WorklistInserter : public SelectionDAG::DAGUpdateListener {
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();
@@ -864,16 +866,22 @@ class EmptyMatchContext {
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);
@@ -966,6 +974,12 @@ class VPMatchContext {
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
@@ -15048,7 +15062,7 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
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>;
@@ -15059,9 +15073,9 @@ SDValue DAGCombiner::visitFADDForFMACombine(SDNode *N) {
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)
More information about the llvm-commits
mailing list