Debian Codegraph @

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