| 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 |
# Description |
| 18 |
# |
| 19 |
# Add an option that would allow us to roll back the limit of recursive AA |
| 20 |
# queries, and thus avoid stack overflows for LoopOpt-intensive cases. The |
| 21 |
# patch retains the default value set within LLORG commit 1d9f4903c. |
| 22 |
# TODO: Once upstreamed, update with LLORG revision & adjust per community review. |
| 23 |
# A better, but heavier long-term fix would involve a complete rework of |
| 24 |
# BasicAA iteration logic so as to avoid recursion altogether. |
| 25 |
|
| 26 |
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp |
| 27 |
index 0a0b53796..76365c38a 100644 |
| 28 |
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp |
| 29 |
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp |
| 30 |
@@ -69,6 +69,11 @@ using namespace llvm; |
| 31 |
static cl::opt<bool> EnableRecPhiAnalysis("basic-aa-recphi", cl::Hidden, |
| 32 |
cl::init(true)); |
| 33 |
|
| 34 |
+/// Limit depth of reqursive AA queries. The limit is set to be large enough so |
| 35 |
+/// that it's hit very rarely, yet small enough to avoid stack overflows. |
| 36 |
+static cl::opt<unsigned> AAQueryDepthLimit("basic-aa-max-query-depth", cl::Hidden, |
| 37 |
+ cl::init(512)); |
| 38 |
+ |
| 39 |
/// SearchLimitReached / SearchTimes shows how often the limit of |
| 40 |
/// to decompose GEPs is reached. It will affect the precision |
| 41 |
/// of basic alias analysis. |
| 42 |
@@ -1628,10 +1633,8 @@ AliasResult BasicAAResult::aliasCheck(const Value *V1, LocationSize V1Size, |
| 43 |
} |
| 44 |
|
| 45 |
// FIXME: If this depth limit is hit, then we may cache sub-optimal results |
| 46 |
- // for recursive queries. For this reason, this limit is chosen to be large |
| 47 |
- // enough to be very rarely hit, while still being small enough to avoid |
| 48 |
- // stack overflows. |
| 49 |
- if (AAQI.Depth >= 512) |
| 50 |
+ // for recursive queries. |
| 51 |
+ if (AAQI.Depth >= AAQueryDepthLimit) |
| 52 |
return AliasResult::MayAlias; |
| 53 |
|
| 54 |
// Check the cache before climbing up use-def chains. This also terminates |