| 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 1c9ce4cd08ecebf4e390ca83d673e69fcad56440 Mon Sep 17 00:00:00 2001 |
| 18 |
From: Florian Hahn <[email protected]> |
| 19 |
Date: Wed, 14 Dec 2022 11:59:19 +0000 |
| 20 |
Subject: [PATCH 4/5] [SCEV] Cache folded SExt SCEV expressions. |
| 21 |
|
| 22 |
Use FoldID to cache SignExtendExprs that get folded to a different |
| 23 |
SCEV. |
| 24 |
|
| 25 |
Depends on D137505. |
| 26 |
|
| 27 |
Reviewed By: mkazantsev |
| 28 |
|
| 29 |
Differential Revision: https://reviews.llvm.org/D137849 |
| 30 |
--- |
| 31 |
llvm/include/llvm/Analysis/ScalarEvolution.h | 2 ++ |
| 32 |
llvm/lib/Analysis/ScalarEvolution.cpp | 25 ++++++++++++++++++++ |
| 33 |
2 files changed, 27 insertions(+) |
| 34 |
|
| 35 |
diff --git a/llvm/include/llvm/Analysis/ScalarEvolution.h b/llvm/include/llvm/Analysis/ScalarEvolution.h |
| 36 |
index f0c3ba40a8d6..b3136886179e 100644 |
| 37 |
--- a/llvm/include/llvm/Analysis/ScalarEvolution.h |
| 38 |
+++ b/llvm/include/llvm/Analysis/ScalarEvolution.h |
| 39 |
@@ -570,6 +570,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, |
| 48 |
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp |
| 49 |
index 7c745ff07cac..40c7b4bb149f 100644 |
| 50 |
--- a/llvm/lib/Analysis/ScalarEvolution.cpp |
| 51 |
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp |
| 52 |
@@ -1914,6 +1914,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; |
| 63 |
+ |
| 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); |
| 69 |
+ } |
| 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( |
| 84 |
-- |
| 85 |
2.34.1 |
| 86 |
|