Skip to content

Commit 86abd53

Browse files
author
Vidush Singhal
committed
fix if you can't hoist address computation
1 parent 81af937 commit 86abd53

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

llvm/lib/Transforms/Instrumentation/GPUSan.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,9 @@ bool GPUSanImpl::instrumentFunction(Function &Fn) {
13471347
SmallVector<CallInst *> Calls;
13481348
SmallVector<GetElementPtrInst *> GEPs;
13491349

1350+
SmallVector<StoreInst *> Stores;
1351+
SmallVector<LoadInst *> Loads;
1352+
13501353
for (auto I = BB->begin(); I != BB->end(); I++) {
13511354

13521355
switch (I->getOpcode()) {
@@ -1358,10 +1361,12 @@ bool GPUSanImpl::instrumentFunction(Function &Fn) {
13581361
}
13591362
case Instruction::Load:
13601363
LoadsStores.push_back(&*I);
1364+
Loads.push_back(cast<LoadInst>(&*I));
13611365
Changed = true;
13621366
break;
13631367
case Instruction::Store:
13641368
LoadsStores.push_back(&*I);
1369+
Stores.push_back(cast<StoreInst>(&*I));
13651370
Changed = true;
13661371
break;
13671372
case Instruction::GetElementPtr:
@@ -1408,7 +1413,26 @@ bool GPUSanImpl::instrumentFunction(Function &Fn) {
14081413
Inst->moveAfter(LatestDependency);
14091414
}
14101415

1411-
instrumentMultipleAccessPerBasicBlock(LI, LoadsStores);
1416+
bool CanMergeChecks = true;
1417+
for (auto *GEP : GEPs) {
1418+
1419+
if (GEP->comesBefore(LoadsStores.front())) {
1420+
CanMergeChecks = CanMergeChecks && true;
1421+
} else {
1422+
CanMergeChecks = CanMergeChecks && false;
1423+
}
1424+
}
1425+
1426+
// check if you can merge various pointer checks.
1427+
if (CanMergeChecks) {
1428+
instrumentMultipleAccessPerBasicBlock(LI, LoadsStores);
1429+
} else {
1430+
for (auto *Load : Loads)
1431+
instrumentLoadInst(LI, *Load);
1432+
for (auto *Store : Stores)
1433+
instrumentStoreInst(LI, *Store);
1434+
}
1435+
14121436
for (auto *GEP : GEPs)
14131437
instrumentGEPInst(LI, *GEP);
14141438
for (auto *Call : Calls)

0 commit comments

Comments
 (0)