Skip to content

Commit 31922b1

Browse files
pszymichfda0
authored andcommitted
Move LLVM 15 patches to interim configuration
--------------------------- (cherry picked from commit 7f90b52)
1 parent b994beb commit 31922b1

19 files changed

+594
-347
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 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+
From 6164d7ef36755d5addf029da753cc41606e64a6f Mon Sep 17 00:00:00 2001
18+
From: Max Kazantsev <[email protected]>
19+
Date: Mon, 19 Sep 2022 17:37:17 +0700
20+
Subject: [PATCH 1/5] [SCEV] Verify contents of loop disposition cache
21+
22+
It seems that it is sometimes broken. Initial motivation for this was
23+
investigation of https://github.com/llvm/llvm-project/issues/56260, but
24+
it also seems that we have found an unrelated bug in LoopFusion that leaves
25+
broken caches.
26+
27+
Differential Revision: https://reviews.llvm.org/D134158
28+
Reviewed By: nikic
29+
---
30+
llvm/lib/Analysis/ScalarEvolution.cpp | 18 ++++++++++++++++++
31+
1 file changed, 18 insertions(+)
32+
33+
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
34+
index 2958a5054afc..76074c715cf7 100644
35+
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
36+
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
37+
@@ -13892,6 +13892,24 @@ void ScalarEvolution::verify() const {
38+
};
39+
VerifyBECountUsers(/* Predicated */ false);
40+
VerifyBECountUsers(/* Predicated */ true);
41+
+
42+
+ // Verify intergity of loop disposition cache.
43+
+ for (const auto &It : LoopDispositions) {
44+
+ const SCEV *S = It.first;
45+
+ auto &Values = It.second;
46+
+ for (auto &V : Values) {
47+
+ auto CachedDisposition = V.getInt();
48+
+ const auto *Loop = V.getPointer();
49+
+ const auto RecomputedDisposition = SE2.getLoopDisposition(S, Loop);
50+
+ if (CachedDisposition != RecomputedDisposition) {
51+
+ dbgs() << "Cached disposition of " << *S << " for loop " << *Loop
52+
+ << " is incorrect: cached "
53+
+ << loopDispositionToStr(CachedDisposition) << ", actual "
54+
+ << loopDispositionToStr(RecomputedDisposition) << "\n";
55+
+ std::abort();
56+
+ }
57+
+ }
58+
+ }
59+
}
60+
61+
bool ScalarEvolution::invalidate(
62+
--
63+
2.34.1
64+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*========================== begin_copyright_notice ============================
2+
3+
Copyright (C) 2024 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+
From f41249dc86ead5cb54a6b5394c086aa79dbeb687 Mon Sep 17 00:00:00 2001
18+
From: Florian Hahn <[email protected]>
19+
Date: Mon, 10 Oct 2022 20:42:18 +0100
20+
Subject: [PATCH 2/5] [SCEV] Verify block disposition cache.
21+
22+
This extends the existing SCEV verification to catch cache invalidation
23+
issues as in #57837.
24+
25+
The validation logic is similar to the recently added loop disposition
26+
cache validation in bb68b2402daa9.
27+
28+
Reviewed By: nikic
29+
30+
Differential Revision: https://reviews.llvm.org/D134531
31+
---
32+
llvm/lib/Analysis/ScalarEvolution.cpp | 16 ++++++++++++++++
33+
1 file changed, 16 insertions(+)
34+
35+
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
36+
index 76074c715cf7..3ea6f61c7021 100644
37+
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
38+
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
39+
@@ -13910,6 +13910,22 @@ void ScalarEvolution::verify() const {
40+
}
41+
}
42+
}
43+
+
44+
+ // Verify integrity of the block disposition cache.
45+
+ for (const auto &It : BlockDispositions) {
46+
+ const SCEV *S = It.first;
47+
+ auto &Values = It.second;
48+
+ for (auto &V : Values) {
49+
+ auto CachedDisposition = V.getInt();
50+
+ const BasicBlock *BB = V.getPointer();
51+
+ const auto RecomputedDisposition = SE2.getBlockDisposition(S, BB);
52+
+ if (CachedDisposition != RecomputedDisposition) {
53+
+ dbgs() << "Cached disposition of " << *S << " for block %"
54+
+ << BB->getName() << " is incorrect! \n";
55+
+ std::abort();
56+
+ }
57+
+ }
58+
+ }
59+
}
60+
61+
bool ScalarEvolution::invalidate(
62+
--
63+
2.34.1
64+

external/llvm/trunk/patches_external/0006-SCEV-Cache-ZExt-SCEV-expressions.patch renamed to external/llvm/trunk/patches_external/0003-SCEV-Cache-ZExt-SCEV-expressions.patch

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SPDX-License-Identifier: Apache-2.0 with LLVM-exception
1414

1515
============================= end_copyright_notice ===========================*/
1616

17-
From 65fb672dce4a7f2df0df7626ec3a18d6cbc73090 Mon Sep 17 00:00:00 2001
17+
From 926869982768eae1af7e9ae3fe7c63270296aec6 Mon Sep 17 00:00:00 2001
1818
From: Florian Hahn <[email protected]>
1919
Date: Fri, 9 Dec 2022 22:14:03 +0000
2020
Subject: [PATCH 3/5] [SCEV] Cache ZExt SCEV expressions.
@@ -55,10 +55,10 @@ Differential Revision: https://reviews.llvm.org/D137505
5555
2 files changed, 134 insertions(+)
5656

5757
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
58-
index b16aa7017719..f0c3ba40a8d6 100644
58+
index fd00c744840b..c8f9a871a5a7 100644
5959
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
6060
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
61-
@@ -567,6 +567,8 @@ public:
61+
@@ -562,6 +562,8 @@ public:
6262
const SCEV *getPtrToIntExpr(const SCEV *Op, Type *Ty);
6363
const SCEV *getTruncateExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
6464
const SCEV *getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
@@ -67,7 +67,7 @@ index b16aa7017719..f0c3ba40a8d6 100644
6767
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
6868
const SCEV *getCastExpr(SCEVTypes Kind, const SCEV *Op, Type *Ty);
6969
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
70-
@@ -1209,6 +1211,45 @@ public:
70+
@@ -1206,6 +1208,45 @@ public:
7171
/// to be infinite, it must also be undefined.
7272
bool loopIsFiniteByAssumption(const Loop *L);
7373

@@ -113,7 +113,7 @@ index b16aa7017719..f0c3ba40a8d6 100644
113113
private:
114114
/// A CallbackVH to arrange for ScalarEvolution to be notified whenever a
115115
/// Value is deleted.
116-
@@ -1289,6 +1330,11 @@ private:
116+
@@ -1267,6 +1308,11 @@ private:
117117
/// This is a cache of the values we have analyzed so far.
118118
ValueExprMapType ValueExprMap;
119119

@@ -125,7 +125,7 @@ index b16aa7017719..f0c3ba40a8d6 100644
125125
/// Mark predicate values currently being processed by isImpliedCond.
126126
SmallPtrSet<const Value *, 6> PendingLoopPredicates;
127127

128-
@@ -2263,6 +2309,28 @@ private:
128+
@@ -2268,6 +2314,28 @@ private:
129129
const SCEV *BackedgeCount = nullptr;
130130
};
131131

@@ -155,10 +155,10 @@ index b16aa7017719..f0c3ba40a8d6 100644
155155

156156
#endif // LLVM_ANALYSIS_SCALAREVOLUTION_H
157157
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
158-
index 495cd73d8eef..7c745ff07cac 100644
158+
index 3ea6f61c7021..847d72828570 100644
159159
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
160160
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
161-
@@ -1587,6 +1587,30 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
161+
@@ -1599,6 +1599,30 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
162162
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
163163
Ty = getEffectiveSCEVType(Ty);
164164

@@ -189,7 +189,7 @@ index 495cd73d8eef..7c745ff07cac 100644
189189
// Fold if the operand is constant.
190190
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
191191
return getConstant(
192-
@@ -7840,6 +7864,8 @@ void ScalarEvolution::forgetAllLoops() {
192+
@@ -8259,6 +8283,8 @@ void ScalarEvolution::forgetAllLoops() {
193193
HasRecMap.clear();
194194
MinTrailingZerosCache.clear();
195195
PredicatedSCEVRewrites.clear();
@@ -198,7 +198,7 @@ index 495cd73d8eef..7c745ff07cac 100644
198198
}
199199

200200
void ScalarEvolution::forgetLoop(const Loop *L) {
201-
@@ -13236,6 +13262,12 @@ void ScalarEvolution::forgetMemoizedResultsImpl(const SCEV *S) {
201+
@@ -13614,6 +13640,12 @@ void ScalarEvolution::forgetMemoizedResultsImpl(const SCEV *S) {
202202
forgetBackedgeTakenCounts(Pair.getPointer(), Pair.getInt());
203203
BECountUsers.erase(BEUsersIt);
204204
}
@@ -211,7 +211,7 @@ index 495cd73d8eef..7c745ff07cac 100644
211211
}
212212

213213
void
214-
@@ -13483,6 +13515,40 @@ void ScalarEvolution::verify() const {
214+
@@ -13926,6 +13958,40 @@ void ScalarEvolution::verify() const {
215215
}
216216
}
217217
}

external/llvm/trunk/patches_external/0004-SCEV-Cache-ZExt-SCEV-expressions.patch

Lines changed: 58 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,51 +14,73 @@ SPDX-License-Identifier: Apache-2.0 with LLVM-exception
1414

1515
============================= end_copyright_notice ===========================*/
1616

17-
From e151e07932d68201fe228508fe776f7550150665 Mon Sep 17 00:00:00 2001
18-
From: Max Kazantsev <mkazantsev@azul.com>
19-
Date: Mon, 19 Sep 2022 17:37:17 +0700
20-
Subject: [PATCH 1/5] [SCEV] Verify contents of loop disposition cache
17+
From 85a1763970eeac7e3410ef3b12d6abb84b9324c4 Mon Sep 17 00:00:00 2001
18+
From: Florian Hahn <flo@fhahn.com>
19+
Date: Wed, 14 Dec 2022 11:59:19 +0000
20+
Subject: [PATCH 4/5] [SCEV] Cache folded SExt SCEV expressions.
2121

22-
It seems that it is sometimes broken. Initial motivation for this was
23-
investigation of https://github.com/llvm/llvm-project/issues/56260, but
24-
it also seems that we have found an unrelated bug in LoopFusion that leaves
25-
broken caches.
22+
Use FoldID to cache SignExtendExprs that get folded to a different
23+
SCEV.
2624

27-
Differential Revision: https://reviews.llvm.org/D134158
28-
Reviewed By: nikic
25+
Depends on D137505.
26+
27+
Reviewed By: mkazantsev
28+
29+
Differential Revision: https://reviews.llvm.org/D137849
2930
---
30-
llvm/lib/Analysis/ScalarEvolution.cpp | 18 ++++++++++++++++++
31-
1 file changed, 18 insertions(+)
31+
llvm/include/llvm/Analysis/ScalarEvolution.h | 2 ++
32+
llvm/lib/Analysis/ScalarEvolution.cpp | 25 ++++++++++++++++++++
33+
2 files changed, 27 insertions(+)
3234

35+
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h
36+
index c8f9a871a5a7..fbc393ebb271 100644
37+
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h
38+
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h
39+
@@ -565,6 +565,8 @@ public:
40+
const SCEV *getZeroExtendExprImpl(const SCEV *Op, Type *Ty,
41+
unsigned Depth = 0);
42+
const SCEV *getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth = 0);
43+
+ const SCEV *getSignExtendExprImpl(const SCEV *Op, Type *Ty,
44+
+ unsigned Depth = 0);
45+
const SCEV *getCastExpr(SCEVTypes Kind, const SCEV *Op, Type *Ty);
46+
const SCEV *getAnyExtendExpr(const SCEV *Op, Type *Ty);
47+
const SCEV *getAddExpr(SmallVectorImpl<const SCEV *> &Ops,
3348
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
34-
index 977fc0911355..1d887d4b60c9 100644
49+
index 847d72828570..ba49e12f958c 100644
3550
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
3651
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
37-
@@ -13449,6 +13449,24 @@ void ScalarEvolution::verify() const {
38-
};
39-
VerifyBECountUsers(/* Predicated */ false);
40-
VerifyBECountUsers(/* Predicated */ true);
52+
@@ -1925,6 +1925,31 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
53+
assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
54+
Ty = getEffectiveSCEVType(Ty);
55+
56+
+ FoldID ID;
57+
+ ID.addInteger(scSignExtend);
58+
+ ID.addPointer(Op);
59+
+ ID.addPointer(Ty);
60+
+ auto Iter = FoldCache.find(ID);
61+
+ if (Iter != FoldCache.end())
62+
+ return Iter->second;
4163
+
42-
+ // Verify intergity of loop disposition cache.
43-
+ for (const auto &It : LoopDispositions) {
44-
+ const SCEV *S = It.first;
45-
+ auto &Values = It.second;
46-
+ for (auto &V : Values) {
47-
+ auto CachedDisposition = V.getInt();
48-
+ const auto *Loop = V.getPointer();
49-
+ const auto RecomputedDisposition = SE2.getLoopDisposition(S, Loop);
50-
+ if (CachedDisposition != RecomputedDisposition) {
51-
+ dbgs() << "Cached disposition of " << *S << " for loop " << *Loop
52-
+ << " is incorrect: cached "
53-
+ << loopDispositionToStr(CachedDisposition) << ", actual "
54-
+ << loopDispositionToStr(RecomputedDisposition) << "\n";
55-
+ std::abort();
56-
+ }
57-
+ }
64+
+ const SCEV *S = getSignExtendExprImpl(Op, Ty, Depth);
65+
+ if (!isa<SCEVSignExtendExpr>(S)) {
66+
+ FoldCache.insert({ID, S});
67+
+ auto R = FoldCacheUser.insert({S, {}});
68+
+ R.first->second.push_back(ID);
5869
+ }
59-
}
60-
61-
bool ScalarEvolution::invalidate(
70+
+ return S;
71+
+}
72+
+
73+
+const SCEV *ScalarEvolution::getSignExtendExprImpl(const SCEV *Op, Type *Ty,
74+
+ unsigned Depth) {
75+
+ assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) &&
76+
+ "This is not an extending conversion!");
77+
+ assert(isSCEVable(Ty) && "This is not a conversion to a SCEVable type!");
78+
+ assert(!Op->getType()->isPointerTy() && "Can't extend pointer!");
79+
+ Ty = getEffectiveSCEVType(Ty);
80+
+
81+
// Fold if the operand is constant.
82+
if (const SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
83+
return getConstant(
6284
--
6385
2.34.1
6486

0 commit comments

Comments
 (0)