Skip to content

Commit 32f5cc5

Browse files
committed
Add direct tests on combiner + infra to disable earlier opts
1 parent 3e34b3e commit 32f5cc5

File tree

4 files changed

+154
-139
lines changed

4 files changed

+154
-139
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,11 @@ class SelectionDAG {
24602460
SDNode *FindNodeOrInsertPos(const FoldingSetNodeID &ID, const SDLoc &DL,
24612461
void *&InsertPos);
24622462

2463+
SDValue getNodeImpl(unsigned Opcode, const SDLoc &DL, EVT VT,
2464+
ArrayRef<SDValue> Ops, SDNodeFlags Flags);
2465+
SDValue getNodeImpl(unsigned Opcode, const SDLoc &DL, SDVTList VTs,
2466+
ArrayRef<SDValue> Ops, SDNodeFlags Flags);
2467+
24632468
/// Maps to auto-CSE operations.
24642469
std::vector<CondCodeSDNode*> CondCodeNodes;
24652470

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@ static cl::opt<bool> EnableVectorFCopySignExtendRound(
153153
"combiner-vector-fcopysign-extend-round", cl::Hidden, cl::init(false),
154154
cl::desc(
155155
"Enable merging extends and rounds into FCOPYSIGN on vector types"));
156+
157+
static cl::opt<bool>
158+
EnableGenericCombines("combiner-generic-combines", cl::Hidden,
159+
cl::init(true),
160+
cl::desc("Enable generic DAGCombine patterns. Useful "
161+
"for testing target-specific combines."));
162+
156163
namespace {
157164

158165
class DAGCombiner {
@@ -251,7 +258,8 @@ namespace {
251258
: DAG(D), TLI(D.getTargetLoweringInfo()),
252259
STI(D.getSubtarget().getSelectionDAGInfo()), OptLevel(OL), AA(AA) {
253260
ForCodeSize = DAG.shouldOptForSize();
254-
DisableGenericCombines = STI && STI->disableGenericCombines(OptLevel);
261+
DisableGenericCombines = !EnableGenericCombines ||
262+
(STI && STI->disableGenericCombines(OptLevel));
255263

256264
MaximumLegalStoreInBits = 0;
257265
// We use the minimum store size here, since that's all we can guarantee

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 53 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ static cl::opt<unsigned>
115115
MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192),
116116
cl::desc("DAG combiner limit number of steps when searching DAG "
117117
"for predecessor nodes"));
118+
static cl::opt<bool> EnableSimplifyNodes(
119+
"selectiondag-simplify-nodes", cl::Hidden, cl::init(true),
120+
cl::desc("Enable SelectionDAG::getNode simplifications. Useful for testing "
121+
"DAG combines."));
118122

119123
static void NewSDValueDbgMsg(SDValue V, StringRef Msg, SelectionDAG *G) {
120124
LLVM_DEBUG(dbgs() << Msg; V.getNode()->dump(G););
@@ -6157,23 +6161,47 @@ static SDValue foldCONCAT_VECTORS(const SDLoc &DL, EVT VT,
61576161
}
61586162

61596163
/// Gets or creates the specified node.
6160-
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT) {
6164+
6165+
SDValue SelectionDAG::getNodeImpl(unsigned Opcode, const SDLoc &DL, EVT VT,
6166+
ArrayRef<SDValue> Ops,
6167+
const SDNodeFlags Flags) {
61616168
SDVTList VTs = getVTList(VT);
6162-
FoldingSetNodeID ID;
6163-
AddNodeIDNode(ID, Opcode, VTs, {});
6164-
void *IP = nullptr;
6165-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP))
6166-
return SDValue(E, 0);
6169+
return getNodeImpl(Opcode, DL, VTs, Ops, Flags);
6170+
}
61676171

6168-
auto *N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
6169-
CSEMap.InsertNode(N, IP);
6172+
SDValue SelectionDAG::getNodeImpl(unsigned Opcode, const SDLoc &DL,
6173+
SDVTList VTs, ArrayRef<SDValue> Ops,
6174+
const SDNodeFlags Flags) {
6175+
SDNode *N;
6176+
// Don't CSE glue-producing nodes
6177+
if (VTs.VTs[VTs.NumVTs - 1] != MVT::Glue) {
6178+
FoldingSetNodeID ID;
6179+
AddNodeIDNode(ID, Opcode, VTs, Ops);
6180+
void *IP = nullptr;
6181+
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
6182+
E->intersectFlagsWith(Flags);
6183+
return SDValue(E, 0);
6184+
}
61706185

6186+
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
6187+
createOperands(N, Ops);
6188+
CSEMap.InsertNode(N, IP);
6189+
} else {
6190+
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
6191+
createOperands(N, Ops);
6192+
}
6193+
6194+
N->setFlags(Flags);
61716195
InsertNode(N);
61726196
SDValue V = SDValue(N, 0);
61736197
NewSDValueDbgMsg(V, "Creating new node: ", this);
61746198
return V;
61756199
}
61766200

6201+
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT) {
6202+
return getNodeImpl(Opcode, DL, VT, {}, SDNodeFlags{});
6203+
}
6204+
61776205
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
61786206
SDValue N1) {
61796207
SDNodeFlags Flags;
@@ -6185,6 +6213,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
61856213
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
61866214
SDValue N1, const SDNodeFlags Flags) {
61876215
assert(N1.getOpcode() != ISD::DELETED_NODE && "Operand is DELETED_NODE!");
6216+
if (!EnableSimplifyNodes)
6217+
return getNodeImpl(Opcode, DL, VT, {N1}, Flags);
61886218

61896219
// Constant fold unary operations with a vector integer or float operand.
61906220
switch (Opcode) {
@@ -6501,31 +6531,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
65016531
break;
65026532
}
65036533

6504-
SDNode *N;
6505-
SDVTList VTs = getVTList(VT);
6506-
SDValue Ops[] = {N1};
6507-
if (VT != MVT::Glue) { // Don't CSE glue producing nodes
6508-
FoldingSetNodeID ID;
6509-
AddNodeIDNode(ID, Opcode, VTs, Ops);
6510-
void *IP = nullptr;
6511-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
6512-
E->intersectFlagsWith(Flags);
6513-
return SDValue(E, 0);
6514-
}
6515-
6516-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
6517-
N->setFlags(Flags);
6518-
createOperands(N, Ops);
6519-
CSEMap.InsertNode(N, IP);
6520-
} else {
6521-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
6522-
createOperands(N, Ops);
6523-
}
6524-
6525-
InsertNode(N);
6526-
SDValue V = SDValue(N, 0);
6527-
NewSDValueDbgMsg(V, "Creating new node: ", this);
6528-
return V;
6534+
return getNodeImpl(Opcode, DL, VT, {N1}, Flags);
65296535
}
65306536

65316537
static std::optional<APInt> FoldValue(unsigned Opcode, const APInt &C1,
@@ -7219,6 +7225,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
72197225
assert(N1.getOpcode() != ISD::DELETED_NODE &&
72207226
N2.getOpcode() != ISD::DELETED_NODE &&
72217227
"Operand is DELETED_NODE!");
7228+
if (!EnableSimplifyNodes)
7229+
return getNodeImpl(Opcode, DL, VT, {N1, N2}, Flags);
72227230

72237231
canonicalizeCommutativeBinop(Opcode, N1, N2);
72247232

@@ -7665,32 +7673,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
76657673
}
76667674
}
76677675

7668-
// Memoize this node if possible.
7669-
SDNode *N;
7670-
SDVTList VTs = getVTList(VT);
7671-
SDValue Ops[] = {N1, N2};
7672-
if (VT != MVT::Glue) {
7673-
FoldingSetNodeID ID;
7674-
AddNodeIDNode(ID, Opcode, VTs, Ops);
7675-
void *IP = nullptr;
7676-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
7677-
E->intersectFlagsWith(Flags);
7678-
return SDValue(E, 0);
7679-
}
7680-
7681-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
7682-
N->setFlags(Flags);
7683-
createOperands(N, Ops);
7684-
CSEMap.InsertNode(N, IP);
7685-
} else {
7686-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
7687-
createOperands(N, Ops);
7688-
}
7689-
7690-
InsertNode(N);
7691-
SDValue V = SDValue(N, 0);
7692-
NewSDValueDbgMsg(V, "Creating new node: ", this);
7693-
return V;
7676+
return getNodeImpl(Opcode, DL, VT, {N1, N2}, Flags);
76947677
}
76957678

76967679
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
@@ -7708,6 +7691,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
77087691
N2.getOpcode() != ISD::DELETED_NODE &&
77097692
N3.getOpcode() != ISD::DELETED_NODE &&
77107693
"Operand is DELETED_NODE!");
7694+
if (!EnableSimplifyNodes)
7695+
return getNodeImpl(Opcode, DL, VT, {N1, N2, N3}, Flags);
7696+
77117697
// Perform various simplifications.
77127698
switch (Opcode) {
77137699
case ISD::FMA:
@@ -7862,33 +7848,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
78627848
break;
78637849
}
78647850
}
7865-
7866-
// Memoize node if it doesn't produce a glue result.
7867-
SDNode *N;
7868-
SDVTList VTs = getVTList(VT);
7869-
SDValue Ops[] = {N1, N2, N3};
7870-
if (VT != MVT::Glue) {
7871-
FoldingSetNodeID ID;
7872-
AddNodeIDNode(ID, Opcode, VTs, Ops);
7873-
void *IP = nullptr;
7874-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
7875-
E->intersectFlagsWith(Flags);
7876-
return SDValue(E, 0);
7877-
}
7878-
7879-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
7880-
N->setFlags(Flags);
7881-
createOperands(N, Ops);
7882-
CSEMap.InsertNode(N, IP);
7883-
} else {
7884-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
7885-
createOperands(N, Ops);
7886-
}
7887-
7888-
InsertNode(N);
7889-
SDValue V = SDValue(N, 0);
7890-
NewSDValueDbgMsg(V, "Creating new node: ", this);
7891-
return V;
7851+
return getNodeImpl(Opcode, DL, VT, {N1, N2, N3}, Flags);
78927852
}
78937853

78947854
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
@@ -10329,6 +10289,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1032910289

1033010290
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1033110291
ArrayRef<SDValue> Ops, const SDNodeFlags Flags) {
10292+
1033210293
unsigned NumOps = Ops.size();
1033310294
switch (NumOps) {
1033410295
case 0: return getNode(Opcode, DL, VT);
@@ -10343,6 +10304,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1034310304
assert(Op.getOpcode() != ISD::DELETED_NODE &&
1034410305
"Operand is DELETED_NODE!");
1034510306
#endif
10307+
if (!EnableSimplifyNodes)
10308+
return getNodeImpl(Opcode, DL, VT, Ops, Flags);
1034610309

1034710310
switch (Opcode) {
1034810311
default: break;
@@ -10411,34 +10374,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
1041110374
break;
1041210375
}
1041310376

10414-
// Memoize nodes.
10415-
SDNode *N;
10416-
SDVTList VTs = getVTList(VT);
10417-
10418-
if (VT != MVT::Glue) {
10419-
FoldingSetNodeID ID;
10420-
AddNodeIDNode(ID, Opcode, VTs, Ops);
10421-
void *IP = nullptr;
10422-
10423-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
10424-
E->intersectFlagsWith(Flags);
10425-
return SDValue(E, 0);
10426-
}
10427-
10428-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
10429-
createOperands(N, Ops);
10430-
10431-
CSEMap.InsertNode(N, IP);
10432-
} else {
10433-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTs);
10434-
createOperands(N, Ops);
10435-
}
10436-
10437-
N->setFlags(Flags);
10438-
InsertNode(N);
10439-
SDValue V(N, 0);
10440-
NewSDValueDbgMsg(V, "Creating new node: ", this);
10441-
return V;
10377+
return getNodeImpl(Opcode, DL, VT, Ops, Flags);
1044210378
}
1044310379

1044410380
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL,
@@ -10458,6 +10394,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1045810394
ArrayRef<SDValue> Ops, const SDNodeFlags Flags) {
1045910395
if (VTList.NumVTs == 1)
1046010396
return getNode(Opcode, DL, VTList.VTs[0], Ops, Flags);
10397+
if (!EnableSimplifyNodes)
10398+
return getNodeImpl(Opcode, DL, VTList, Ops, Flags);
1046110399

1046210400
#ifndef NDEBUG
1046310401
for (const auto &Op : Ops)
@@ -10622,30 +10560,7 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
1062210560
#endif
1062310561
}
1062410562

10625-
// Memoize the node unless it returns a glue result.
10626-
SDNode *N;
10627-
if (VTList.VTs[VTList.NumVTs-1] != MVT::Glue) {
10628-
FoldingSetNodeID ID;
10629-
AddNodeIDNode(ID, Opcode, VTList, Ops);
10630-
void *IP = nullptr;
10631-
if (SDNode *E = FindNodeOrInsertPos(ID, DL, IP)) {
10632-
E->intersectFlagsWith(Flags);
10633-
return SDValue(E, 0);
10634-
}
10635-
10636-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTList);
10637-
createOperands(N, Ops);
10638-
CSEMap.InsertNode(N, IP);
10639-
} else {
10640-
N = newSDNode<SDNode>(Opcode, DL.getIROrder(), DL.getDebugLoc(), VTList);
10641-
createOperands(N, Ops);
10642-
}
10643-
10644-
N->setFlags(Flags);
10645-
InsertNode(N);
10646-
SDValue V(N, 0);
10647-
NewSDValueDbgMsg(V, "Creating new node: ", this);
10648-
return V;
10563+
return getNodeImpl(Opcode, DL, VTList, Ops, Flags);
1064910564
}
1065010565

1065110566
SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL,

0 commit comments

Comments
 (0)