Skip to content

Commit bdbd756

Browse files
mmereckiigcbot
authored andcommitted
[LLVM] Fix stack overflow in SCEV
Break recursion in createNodeFromSelectLikePHI.
1 parent 354a7b8 commit bdbd756

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2023 Intel Corporation
4+
5+
SPDX-License-Identifier: MIT
6+
7+
============================= end_copyright_notice ===========================*/
8+
9+
/*========================== begin_copyright_notice ============================
10+
11+
Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
See https://llvm.org/LICENSE.txt for license information.
13+
SPDX-License-Identifier: Apache-2.0 with LLVM-exception
14+
15+
============================= end_copyright_notice ===========================*/
16+
17+
# TODO: Once upstreamed, update with LLORG revision & adjust per community review
18+
19+
diff -Naur "a/llvm/include/llvm/Analysis/ScalarEvolution.h" "b/llvm/include/llvm/Analysis/ScalarEvolution.h"
20+
--- "a/llvm/include/llvm/Analysis/ScalarEvolution.h" 2023-12-19 12:51:55.043965800 +0100
21+
+++ "b/llvm/include/llvm/Analysis/ScalarEvolution.h" 2023-12-19 12:28:39.120139600 +0100
22+
@@ -1295,6 +1295,9 @@
23+
/// Set of Phis processed in createSCEVIter.
24+
SmallPtrSet<const PHINode*, 6> PendingPhiSCEVIter;
25+
26+
+ /// Set of Phis processed in createPhiNodeFromSelectLikePHI.
27+
+ SmallPtrSet<const PHINode*, 6> PendingPhiNodeFromSelectLikePHI;
28+
+
29+
/// Mark SCEVUnknown Phis currently being processed by getRangeRef.
30+
SmallPtrSet<const PHINode *, 6> PendingPhiRanges;
31+
32+
diff -Naur "a/llvm/lib/Analysis/ScalarEvolution.cpp" "b/llvm/lib/Analysis/ScalarEvolution.cpp"
33+
--- "a/llvm/lib/Analysis/ScalarEvolution.cpp" 2023-12-19 12:52:55.207074600 +0100
34+
+++ "b/llvm/lib/Analysis/ScalarEvolution.cpp" 2023-12-19 12:37:39.188525900 +0100
35+
@@ -5836,11 +5836,18 @@
36+
auto *BI = dyn_cast<BranchInst>(IDom->getTerminator());
37+
Value *Cond = nullptr, *LHS = nullptr, *RHS = nullptr;
38+
39+
- if (BI && BI->isConditional() &&
40+
- BrPHIToSelect(DT, BI, PN, Cond, LHS, RHS) &&
41+
- IsAvailableOnEntry(L, DT, getSCEV(LHS), PN->getParent()) &&
42+
- IsAvailableOnEntry(L, DT, getSCEV(RHS), PN->getParent()))
43+
- return createNodeForSelectOrPHI(PN, Cond, LHS, RHS);
44+
+ // do not run over cycled PHIs while processing createNodeFromSelectLikePHI
45+
+ if (PendingPhiNodeFromSelectLikePHI.insert(PN).second) {
46+
+ const SCEV* S = nullptr;
47+
+ if (BI && BI->isConditional() &&
48+
+ BrPHIToSelect(DT, BI, PN, Cond, LHS, RHS) &&
49+
+ IsAvailableOnEntry(L, DT, getSCEV(LHS), PN->getParent()) &&
50+
+ IsAvailableOnEntry(L, DT, getSCEV(RHS), PN->getParent())) {
51+
+ S = createNodeForSelectOrPHI(PN, Cond, LHS, RHS);
52+
+ }
53+
+ PendingPhiNodeFromSelectLikePHI.erase(PN);
54+
+ return S;
55+
+ }
56+
}
57+
58+
return nullptr;

0 commit comments

Comments
 (0)