summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2021-04-30 22:38:40 +0200
committerTom Stellard <tstellar@redhat.com>2021-06-14 14:11:05 -0400
commitce779098006e9de32678f28140f22de7e4a19189 (patch)
treed54b920cea57bcd952b5238dda113b0b36b17ecf
parent5b149c437194d10877e9e45b3d8cc9252af1944b (diff)
downloadllvm-ce779098006e9de32678f28140f22de7e4a19189.tar.gz
[ValueTracking] Limit scan when checking poison UB (PR50155)
The current code can scan an unlimited number of instructions, if the containing basic block is very large. The test case from PR50155 contains a basic block with approximately 100k instructions. To avoid this, limit the number of instructions we inspect. At the same time, drop the limit on the number of basic blocks, as this will be implicitly limited by the number of instructions as well. (cherry picked from commit 2cd78686055f1badb9aa55cb95e189548ffc82f0)
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index e174c5efe424..75486d3c80e7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -5150,6 +5150,9 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
return false;
}
+ // Limit number of instructions we look at, to avoid scanning through large
+ // blocks. The current limit is chosen arbitrarily.
+ unsigned ScanLimit = 32;
BasicBlock::const_iterator End = BB->end();
if (!PoisonOnly) {
@@ -5160,6 +5163,11 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
// For example, 'udiv x, (undef | 1)' isn't UB.
for (auto &I : make_range(Begin, End)) {
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ if (--ScanLimit == 0)
+ break;
+
if (const auto *CB = dyn_cast<CallBase>(&I)) {
for (unsigned i = 0; i < CB->arg_size(); ++i) {
if (CB->paramHasAttr(i, Attribute::NoUndef) &&
@@ -5186,9 +5194,12 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
for_each(V->users(), Propagate);
Visited.insert(BB);
- unsigned Iter = 0;
- while (Iter++ < MaxAnalysisRecursionDepth) {
+ while (true) {
for (auto &I : make_range(Begin, End)) {
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ if (--ScanLimit == 0)
+ return false;
if (mustTriggerUB(&I, YieldsPoison))
return true;
if (!isGuaranteedToTransferExecutionToSuccessor(&I))