[llvm] 8999662 - [InstCombine] Limit use walk in copied from constant fold
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 11 08:20:53 PST 2023
Author: Nikita Popov
Date: 2023-01-11T17:17:46+01:00
New Revision: 89996621de073e43de7bed552037b10d2a0fdf80
URL: https://github.com/llvm/llvm-project/commit/89996621de073e43de7bed552037b10d2a0fdf80
DIFF: https://github.com/llvm/llvm-project/commit/89996621de073e43de7bed552037b10d2a0fdf80.diff
LOG: [InstCombine] Limit use walk in copied from constant fold
This fold currently performs an unbounded recursive use walk.
Make sure that we don't visit too many instructions (the limit is
chosen arbitrarily).
This is with an eye on also handling phi nodes, which will further
extend the considered use graph.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index 3feeeaf0063b..8c9b027bd07c 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -28,9 +28,14 @@ using namespace PatternMatch;
#define DEBUG_TYPE "instcombine"
-STATISTIC(NumDeadStore, "Number of dead stores eliminated");
+STATISTIC(NumDeadStore, "Number of dead stores eliminated");
STATISTIC(NumGlobalCopies, "Number of allocas copied from constant global");
+static cl::opt<unsigned> MaxCopiedFromConstantUsers(
+ "instcombine-max-copied-from-constant-users", cl::init(128),
+ cl::desc("Maximum users to visit in copy from constant transform"),
+ cl::Hidden);
+
/// isOnlyCopiedFromConstantMemory - Recursively walk the uses of a (derived)
/// pointer to an alloca. Ignore any reads of the pointer, return false if we
/// see any stores or other unknown uses. If we see pointer arithmetic, keep
@@ -54,6 +59,8 @@ isOnlyCopiedFromConstantMemory(AAResults *AA, AllocaInst *V,
ValueAndIsOffset Elem = Worklist.pop_back_val();
if (!Visited.insert(Elem).second)
continue;
+ if (Visited.size() > MaxCopiedFromConstantUsers)
+ return false;
const auto [Value, IsOffset] = Elem;
for (auto &U : Value->uses()) {
More information about the llvm-commits
mailing list