Running -jump-threading twice crashes opt in ValueHandleBase::ValueIsDeleted
| Bugzilla Link | 24517 |
| Resolution | WORKSFORME |
| Resolved on | Jul 04, 2016 03:59 |
| Version | trunk |
| OS | Linux |
| Attachments | Reproducer |
| CC | @bcardosolopes,@majnemer,@hfinkel,@uabjean,@mveriksson,@mikaelholmen |
Extended Description
Running
build-all/bin/opt -S ./bugpoint-reduced-simplified.ll -jump-threading -jump-threading
on the attached bugpoint-reduced ll-file ends with
While deleting: label %bb1 An asserting value handle still pointed to this value! UNREACHABLE executed at ../lib/IR/Value.cpp:686!
It's on the second invocation of jump-threading that it breaks, when it calls llvm::removeUnreachableBlocks:
0 opt 0x0000000001635faa llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 42 1 opt 0x0000000001635606 llvm::sys::RunSignalHandlers() + 54 2 opt 0x00000000016378fa 3 libpthread.so.0 0x00007f8c62e30340 4 libc.so.6 0x00007f8c62058cc9 gsignal + 57 5 libc.so.6 0x00007f8c6205c0d8 abort + 328 6 opt 0x00000000015f68fd llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 461 7 opt 0x00000000012b8e2b llvm::ValueHandleBase::ValueIsDeleted(llvm::Value*) + 1051 8 opt 0x00000000012b879b llvm::Value::~Value() + 43 9 opt 0x000000000117abb9 llvm::BasicBlock::~BasicBlock() + 9 10 opt 0x000000000167281c llvm::removeUnreachableBlocks(llvm::Function&) + 2940 11 opt 0x00000000014c1667 12 opt 0x0000000001288744 llvm::FPPassManager::runOnFunction(llvm::Function&) + 516 13 opt 0x000000000128898b llvm::FPPassManager::runOnModule(llvm::Module&) + 43 14 opt 0x0000000001288e67 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 903 15 opt 0x0000000000605864 main + 8148 16 libc.so.6 0x00007f8c62043ec5 __libc_start_main + 245 17 opt 0x00000000005f6df2
The code looks like this when jump-threading is invoked the second time:
*** IR Dump Before Jump Threading *** define void @fn1() { .split.us: br label %bb2.us.us
bb2.us.us: ; preds = %bb2.us.us, %.split.us br label %bb2.us.us
bb1.us: ; preds = %bb1.us br label %bb1.us
bb2.us4: ; preds = %bb2.us4 br label %bb2.us4
bb2: ; preds = %bb1 %_tmp3 = icmp slt i16 %_tmp18, 2 br i1 %_tmp3, label %bb1, label %bb1
bb1: ; preds = %bb2, %bb2 %_tmp18 = load i16, i16* @c %_tmp20 = icmp ne i16 %_tmp18, 0 br i1 %_tmp20, label %bb2, label %bb6
bb6: ; preds = %bb1 ret void }
And when it tries to delete bb1 it crashes.
This bug is no longer reproducible.
Looks like JumpThreading relies on other passes to clean up its stuff. Example, it doesn't crash if you use "opt -jump-threading -simplifycfg -jump-threading". Maybe historically this is why -simplifycfg is scheduled after -jump-threading in -O2, etc.
It also doesn't crash if you use "opt -jump-threading | opt -jump-threading". My hunch is that the LVI analysis is invalid after the first -jump-threading pass; this would explain why it crashes if you use "opt -jump-threading -jump-threading" but not when you use two different opt commands.
Looks like JumpThreading relies on other passes to clean up its stuff. Example, it doesn't crash if you use "opt -jump-threading -simplifycfg -jump-threading". Maybe historically this is why -simplifycfg is scheduled after -jump-threading in -O2, etc.
Yes I noticed that too, but I don't understand what is happening because even simplifycfg is running removeUnreachableBlocks(F) first, and that is the function eventually crashing when it's run from jump-threading.
Looks like JumpThreading relies on other passes to clean up its stuff. Example, it doesn't crash if you use "opt -jump-threading -simplifycfg -jump-threading". Maybe historically this is why -simplifycfg is scheduled after -jump-threading in -O2, etc.