Debian Codegraph @

external/llvm/releases/15.0.0/patches_external/0005-SCEV-Cache-ZExt-SCEV-expressions.patch

raw
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 dfa7eaff486b1ec7778069cd22ffc440df208717 Mon Sep 17 00:00:00 2001
18 From: Florian Hahn <[email protected]>
19 Date: Wed, 28 Dec 2022 00:09:52 +0000
20 Subject: [PATCH 5/5] [SCEV] Properly clean up duplicated FoldCacheUser ID
21 entries.
22
23 The current code did not properly handled duplicated FoldCacheUser ID
24 entries when overwriting an existing entry in the FoldCache.
25
26 This triggered verification failures reported by @uabelho and #59721.
27
28 The patch fixes that by removing stale IDs when overwriting an existing
29 entry in the cache.
30
31 Fixes #59721.
32 ---
33 llvm/lib/Analysis/ScalarEvolution.cpp | 37 +++++++++++++++++++--------
34 1 file changed, 27 insertions(+), 10 deletions(-)
35
36 diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
37 index ba49e12f958c..cf76ab7efb65 100644
38 --- a/llvm/lib/Analysis/ScalarEvolution.cpp
39 +++ b/llvm/lib/Analysis/ScalarEvolution.cpp
40 @@ -1590,6 +1590,29 @@ static APInt extractConstantWithoutWrapping(ScalarEvolution &SE,
41 return APInt(BitWidth, 0);
42 }
43
44 +static void insertFoldCacheEntry(
45 + const ScalarEvolution::FoldID &ID, const SCEV *S,
46 + DenseMap<ScalarEvolution::FoldID, const SCEV *> &FoldCache,
47 + DenseMap<const SCEV *, SmallVector<ScalarEvolution::FoldID, 2>>
48 + &FoldCacheUser) {
49 + auto I = FoldCache.insert({ID, S});
50 + if (!I.second) {
51 + // Remove FoldCacheUser entry for ID when replacing an existing FoldCache
52 + // entry.
53 + auto &UserIDs = FoldCacheUser[I.first->second];
54 + assert(count(UserIDs, ID) == 1 && "unexpected duplicates in UserIDs");
55 + for (unsigned I = 0; I != UserIDs.size(); ++I)
56 + if (UserIDs[I] == ID) {
57 + std::swap(UserIDs[I], UserIDs.back());
58 + break;
59 + }
60 + UserIDs.pop_back();
61 + I.first->second = S;
62 + }
63 + auto R = FoldCacheUser.insert({S, {}});
64 + R.first->second.push_back(ID);
65 +}
66 +
67 const SCEV *
68 ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
69 assert(getTypeSizeInBits(Op->getType()) < getTypeSizeInBits(Ty) &&
70 @@ -1608,11 +1631,8 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
71 return Iter->second;
72
73 const SCEV *S = getZeroExtendExprImpl(Op, Ty, Depth);
74 - if (!isa<SCEVZeroExtendExpr>(S)) {
75 - FoldCache.insert({ID, S});
76 - auto R = FoldCacheUser.insert({S, {}});
77 - R.first->second.push_back(ID);
78 - }
79 + if (!isa<SCEVZeroExtendExpr>(S))
80 + insertFoldCacheEntry(ID, S, FoldCache, FoldCacheUser);
81 return S;
82 }
83
84 @@ -1934,11 +1954,8 @@ ScalarEvolution::getSignExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
85 return Iter->second;
86
87 const SCEV *S = getSignExtendExprImpl(Op, Ty, Depth);
88 - if (!isa<SCEVSignExtendExpr>(S)) {
89 - FoldCache.insert({ID, S});
90 - auto R = FoldCacheUser.insert({S, {}});
91 - R.first->second.push_back(ID);
92 - }
93 + if (!isa<SCEVSignExtendExpr>(S))
94 + insertFoldCacheEntry(ID, S, FoldCache, FoldCacheUser);
95 return S;
96 }
97
98 --
99 2.34.1
100