Skip to content

Commit ce77909

Browse files
nikictstellar
authored andcommitted
[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 2cd7868)
1 parent 5b149c4 commit ce77909

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5150,6 +5150,9 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
51505150
return false;
51515151
}
51525152

5153+
// Limit number of instructions we look at, to avoid scanning through large
5154+
// blocks. The current limit is chosen arbitrarily.
5155+
unsigned ScanLimit = 32;
51535156
BasicBlock::const_iterator End = BB->end();
51545157

51555158
if (!PoisonOnly) {
@@ -5160,6 +5163,11 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
51605163
// For example, 'udiv x, (undef | 1)' isn't UB.
51615164

51625165
for (auto &I : make_range(Begin, End)) {
5166+
if (isa<DbgInfoIntrinsic>(I))
5167+
continue;
5168+
if (--ScanLimit == 0)
5169+
break;
5170+
51635171
if (const auto *CB = dyn_cast<CallBase>(&I)) {
51645172
for (unsigned i = 0; i < CB->arg_size(); ++i) {
51655173
if (CB->paramHasAttr(i, Attribute::NoUndef) &&
@@ -5186,9 +5194,12 @@ static bool programUndefinedIfUndefOrPoison(const Value *V,
51865194
for_each(V->users(), Propagate);
51875195
Visited.insert(BB);
51885196

5189-
unsigned Iter = 0;
5190-
while (Iter++ < MaxAnalysisRecursionDepth) {
5197+
while (true) {
51915198
for (auto &I : make_range(Begin, End)) {
5199+
if (isa<DbgInfoIntrinsic>(I))
5200+
continue;
5201+
if (--ScanLimit == 0)
5202+
return false;
51925203
if (mustTriggerUB(&I, YieldsPoison))
51935204
return true;
51945205
if (!isGuaranteedToTransferExecutionToSuccessor(&I))

0 commit comments

Comments
 (0)