Skip to content

Commit edf4e72

Browse files
committed
Fixups
1 parent 3ffca6b commit edf4e72

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

llvm/include/llvm/CodeGen/SelectionDAG.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,9 @@ class SelectionDAG {
455455
// Maximum depth for recursive analysis such as computeKnownBits, etc.
456456
static constexpr unsigned MaxRecursionDepth = 6;
457457

458+
// Returns the maximum depth for SDNode->hasPredecessor() like searches.
459+
static unsigned getHasPredecessorMaxSteps();
460+
458461
explicit SelectionDAG(const TargetMachine &TM, CodeGenOptLevel);
459462
SelectionDAG(const SelectionDAG &) = delete;
460463
SelectionDAG &operator=(const SelectionDAG &) = delete;

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ 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<unsigned int>
158-
MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192),
159-
cl::desc("DAG combiner limit number of steps when searching DAG "
160-
"for predecessor nodes"));
161-
162156
namespace {
163157

164158
class DAGCombiner {
@@ -18929,6 +18923,7 @@ bool DAGCombiner::CombineToPreIndexedLoadStore(SDNode *N) {
1892918923
// can be folded with this one. We should do this to avoid having to keep
1893018924
// a copy of the original base pointer.
1893118925
SmallVector<SDNode *, 16> OtherUses;
18926+
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
1893218927
if (isa<ConstantSDNode>(Offset))
1893318928
for (SDNode::use_iterator UI = BasePtr->use_begin(),
1893418929
UE = BasePtr->use_end();
@@ -19093,6 +19088,7 @@ static bool shouldCombineToPostInc(SDNode *N, SDValue Ptr, SDNode *PtrUse,
1909319088
return false;
1909419089

1909519090
SmallPtrSet<const SDNode *, 32> Visited;
19091+
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
1909619092
for (SDNode *Use : BasePtr->uses()) {
1909719093
if (Use == Ptr.getNode())
1909819094
continue;
@@ -19139,6 +19135,7 @@ static SDNode *getPostIndexedLoadStoreOp(SDNode *N, bool &IsLoad,
1913919135
// 2) Op must be independent of N, i.e. Op is neither a predecessor
1914019136
// nor a successor of N. Otherwise, if Op is folded that would
1914119137
// create a cycle.
19138+
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
1914219139
for (SDNode *Op : Ptr->uses()) {
1914319140
// Check for #1.
1914419141
if (!shouldCombineToPostInc(N, Ptr, Op, BasePtr, Offset, AM, DAG, TLI))

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,17 @@ static cl::opt<int> MaxLdStGlue("ldstmemcpy-glue-max",
111111
cl::desc("Number limit for gluing ld/st of memcpy."),
112112
cl::Hidden, cl::init(0));
113113

114+
static cl::opt<unsigned>
115+
MaxSteps("has-predecessor-max-steps", cl::Hidden, cl::init(8192),
116+
cl::desc("DAG combiner limit number of steps when searching DAG "
117+
"for predecessor nodes"));
118+
114119
static void NewSDValueDbgMsg(SDValue V, StringRef Msg, SelectionDAG *G) {
115120
LLVM_DEBUG(dbgs() << Msg; V.getNode()->dump(G););
116121
}
117122

123+
unsigned SelectionDAG::getHasPredecessorMaxSteps() { return MaxSteps; }
124+
118125
//===----------------------------------------------------------------------===//
119126
// ConstantFPSDNode Class
120127
//===----------------------------------------------------------------------===//
@@ -2487,12 +2494,16 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
24872494
if (Op.getNode() != FPNode)
24882495
Worklist.push_back(Op.getNode());
24892496

2497+
unsigned MaxSteps = SelectionDAG::getHasPredecessorMaxSteps();
24902498
while (!Worklist.empty()) {
24912499
const SDNode *Node = Worklist.pop_back_val();
24922500
auto [_, Inserted] = Visited.insert(Node);
24932501
if (!Inserted)
24942502
continue;
24952503

2504+
if (MaxSteps > 0 && Visited.size() >= MaxSteps)
2505+
return false;
2506+
24962507
// Reached the FPNode (would result in a cycle).
24972508
// OR Reached CALLSEQ_START (would result in nested call sequences).
24982509
if (Node == FPNode || Node->getOpcode() == ISD::CALLSEQ_START)
@@ -2511,7 +2522,8 @@ static bool canFoldStoreIntoLibCallOutputPointers(StoreSDNode *StoreNode,
25112522

25122523
// True if we're outside a call sequence and don't have the FPNode as a
25132524
// predecessor. No cycles or nested call sequences possible.
2514-
return !SDNode::hasPredecessorHelper(FPNode, Visited, DeferredNodes);
2525+
return !SDNode::hasPredecessorHelper(FPNode, Visited, DeferredNodes,
2526+
MaxSteps);
25152527
}
25162528

25172529
bool SelectionDAG::expandMultipleResultFPLibCall(
@@ -2542,7 +2554,7 @@ bool SelectionDAG::expandMultipleResultFPLibCall(
25422554

25432555
// Find users of the node that store the results (and share input chains). The
25442556
// destination pointers can be used instead of creating stack allocations.
2545-
SDValue StoresInChain{};
2557+
SDValue StoresInChain;
25462558
SmallVector<StoreSDNode *, 2> ResultStores(NumResults);
25472559
for (SDNode *User : Node->uses()) {
25482560
if (!ISD::isNormalStore(User))

llvm/test/CodeGen/X86/sincos-stack-args.ll

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
declare double @g(double, double)
66

7-
define double @f(double %a) {
8-
; CHECK-LABEL: f:
7+
; Though not visible within the IR, this will lower to an FSINCOS node, with
8+
; store users, that are within a (callseq_start, callseq_end) pair. In this
9+
; case, the stores cannot be folded into the sincos call.
10+
define double @negative_sincos_with_stores_within_call_sequence(double %a) {
11+
; CHECK-LABEL: negative_sincos_with_stores_within_call_sequence:
912
; CHECK: # %bb.0: # %entry
1013
; CHECK-NEXT: subl $44, %esp
1114
; CHECK-NEXT: .cfi_def_cfa_offset 48

0 commit comments

Comments
 (0)