[PATCH] D90328: Eliminates dead store of an exisiting value
Daniel McCrevan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 6 12:08:26 PST 2020
dmccrevan added a comment.
So actually I just realized that my current implementation I have on this revision isn't correct. For some reason, I must've not noticed the test result is different.
I began to adapt my code to fix it, but I am running into an error. When I use the WorkList/Visited approach, this works and it seems to not increase the amount of time it loops through the code.
This implementation works:
SmallVector<MemoryAccess *, 4> WorkList;
SmallPtrSet<MemoryAccess *, 8> Visited;
auto PushMemUses = [&WorkList, &Visited](MemoryAccess *Acc) {
if (!Visited.insert(Acc).second)
return;
for (Use &U : Acc->uses())
WorkList.push_back(cast<MemoryAccess>(U.getUser()));
};
PushMemUses(Def);
for(auto x : WorkList) {
if(MemoryDef *UseDef = dyn_cast_or_null<MemoryDef>(x)) {
Instruction *UseInst = UseDef->getMemoryInst();
if (!UseInst)
continue;
if (UseInst->isIdenticalTo(DefInst)) {
deleteDeadInstruction(UseInst);
MadeChange = true;
}
}
}
This implementation throws the error below
for (Use &U : DefAccess->uses()) {
if(!U)
continue;
MemoryAccess *UseAccess = dyn_cast_or_null<MemoryAccess>(U.getUser());
if(!UseAccess)
continue;
if (MemoryDef *UseDef = dyn_cast_or_null<MemoryDef>(UseAccess)) {
Instruction *UseInst = UseDef->getMemoryInst();
if (!UseInst)
continue;
if (UseInst->isIdenticalTo(DefInst)) {
deleteDeadInstruction(UseInst);
MadeChange = true;
}
}
}
Stack dump:
0. Program arguments: ./opt -dse -S -debug pr16520.ll
1. Running pass 'Function Pass Manager' on module 'pr16520.ll'.
2. Running pass 'Dead Store Elimination' on function '@_Z1fbRb'
#0 0x000000000366d017 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Support/Unix/Signals.inc:563:22
#1 0x000000000366d0ce PrintStackTraceSignalHandler(void*) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Support/Unix/Signals.inc:630:1
#2 0x000000000366b0ea llvm::sys::RunSignalHandlers() /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Support/Signals.cpp:71:20
#3 0x000000000366ca6a SignalHandler(int) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Support/Unix/Signals.inc:405:1
#4 0x00007fd893bd0a20 __restore_rt (/lib64/libpthread.so.0+0x13a20)
#5 0x00000000008b1b4e llvm::Value::getValueID() const /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/IR/Value.h:529:12
#6 0x000000000222aa83 llvm::MemoryAccess::classof(llvm::Value const*) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Analysis/MemorySSA.h:157:32
#7 0x000000000223d163 llvm::isa_impl<llvm::MemoryAccess, llvm::User, void>::doit(llvm::User const&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:59:3
#8 0x000000000223bcd2 llvm::isa_impl_cl<llvm::MemoryAccess, llvm::User const*>::doit(llvm::User const*) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:106:3
#9 0x000000000223a649 llvm::isa_impl_wrap<llvm::MemoryAccess, llvm::User const*, llvm::User const*>::doit(llvm::User const* const&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:132:3
#10 0x0000000002237ef7 llvm::isa_impl_wrap<llvm::MemoryAccess, llvm::User* const, llvm::User const*>::doit(llvm::User* const&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:124:3
#11 0x0000000002235518 bool llvm::isa<llvm::MemoryAccess, llvm::User*>(llvm::User* const&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:144:1
#12 0x00000000032ab97d llvm::cast_retty<llvm::MemoryAccess, llvm::User*>::ret_type llvm::dyn_cast_or_null<llvm::MemoryAccess, llvm::User>(llvm::User*) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/include/llvm/Support/Casting.h:368:15
#13 0x00000000032a365a (anonymous namespace)::DSEState::eliminateDeadStoresOfExisitingValues() /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp:2431:65
#14 0x00000000032a4e14 (anonymous namespace)::eliminateDeadStoresMemorySSA(llvm::Function&, llvm::AAResults&, llvm::MemorySSA&, llvm::DominatorTree&, llvm::PostDominatorTree&, llvm::TargetLibraryInfo const&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp:2719:14
#15 0x00000000032a533b (anonymous namespace)::DSELegacyPass::runOnFunction(llvm::Function&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp:2795:45
#16 0x0000000002c28b1b llvm::FPPassManager::runOnFunction(llvm::Function&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1519:20
#17 0x0000000002c28d84 llvm::FPPassManager::runOnModule(llvm::Module&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1565:13
#18 0x0000000002c291ae (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1634:20
#19 0x0000000002c247ba llvm::legacy::PassManagerImpl::run(llvm::Module&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:615:13
#20 0x0000000002c29995 llvm::legacy::PassManager::run(llvm::Module&) /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1762:1
#21 0x00000000008e9914 main /home/daniel/Projects/recurse/llvm-stuff/llvm-project/llvm/tools/opt/opt.cpp:973:15
#22 0x00007fd893683e0a __libc_start_main (/lib64/libc.so.6+0x27e0a)
#23 0x00000000008b144a _start /home/abuild/rpmbuild/BUILD/glibc-2.32/csu/../sysdeps/x86_64/start.S:122:0
fish: “./opt -dse -S -debug pr16520.ll” terminated by signal SIGSEGV (Address boundary error)
The line it is throwing the error on is ` MemoryAccess *UseAccess = dyn_cast_or_null<MemoryAccess>(U.getUser());` I tried debugging this, but got no luck, should I stick with the worklist idea? I think it doesn't break because of the visited set, but is this something that i could adapt to the other impl?
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90328/new/
https://reviews.llvm.org/D90328
More information about the llvm-commits
mailing list