bugpoint can't automatically select a safe interpreter!

I tried to reduce the test case in
https://bugs.llvm.org/show_bug.cgi?id=42706. Here it is crashing opt:

$ ~/llvm-debug/bin/opt -use-gpu-divergence-analysis -divergence stripped.ll
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

opt: /home/jayfoad2/git/llvm-project/llvm/lib/Analysis/SyncDependenceAnalysis.cpp:312:
std::unique_ptr<ConstBlockSet>
llvm::DivergencePropagator::computeJoinPoints(const llvm::BasicBlock
&, SuccessorIterable, const llvm::Loop *, const llvm::BasicBlock *)
[SuccessorIterable = llvm::iterator_range<llvm::SuccIterator<const
llvm::Instruction, const llvm::BasicBlock> >]: Assertion
`HeaderDefBlock && "no definition in header of carrying loop"' failed.
Stack dump:
0. Program arguments: /home/jayfoad2/llvm-debug/bin/opt
-use-gpu-divergence-analysis -divergence stripped.ll
1. Running pass 'Function Pass Manager' on module 'stripped.ll'.
2. Running pass 'Legacy Divergence Analysis' on function '@llpc.shader.CS.main'
#0 0x0000000005fa0889 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
/home/jayfoad2/git/llvm-project/llvm/lib/Support/Unix/Signals.inc:533:11
#1 0x0000000005fa0a39 PrintStackTraceSignalHandler(void*)
/home/jayfoad2/git/llvm-project/llvm/lib/Support/Unix/Signals.inc:594:1
#2 0x0000000005f9f276 llvm::sys::RunSignalHandlers()
/home/jayfoad2/git/llvm-project/llvm/lib/Support/Signals.cpp:67:5
#3 0x0000000005fa112b SignalHandler(int)
/home/jayfoad2/git/llvm-project/llvm/lib/Support/Unix/Signals.inc:385:1
#4 0x00007f56aeff0890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
#5 0x00007f56adcb6e97 raise
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
#6 0x00007f56adcb8801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
#7 0x00007f56adca839a __assert_fail_base
/build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
#8 0x00007f56adca8412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
#9 0x0000000004e3db75
std::unique_ptr<llvm::SmallPtrSet<llvm::BasicBlock const*, 4u>,
std::default_delete<llvm::SmallPtrSet<llvm::BasicBlock const*, 4u> > >
llvm::DivergencePropagator::computeJoinPoints<llvm::iterator_range<llvm::SuccIterator<llvm::Instruction
const, llvm::BasicBlock const> > >(llvm::BasicBlock const&,
llvm::iterator_range<llvm::SuccIterator<llvm::Instruction const,
llvm::BasicBlock const> >, llvm::Loop const*, llvm::BasicBlock const*)
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/SyncDependenceAnalysis.cpp:0:7
#10 0x0000000004e3c5e4
llvm::SyncDependenceAnalysis::join_blocks(llvm::Instruction const&)
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/SyncDependenceAnalysis.cpp:381:32
#11 0x0000000004c1abf3
llvm::DivergenceAnalysis::propagateBranchDivergence(llvm::Instruction
const&) /home/jayfoad2/git/llvm-project/llvm/lib/Analysis/DivergenceAnalysis.cpp:311:36
#12 0x0000000004c1b106 llvm::DivergenceAnalysis::compute()
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/DivergenceAnalysis.cpp:386:9
#13 0x0000000004c1b54b
llvm::GPUDivergenceAnalysis::GPUDivergenceAnalysis(llvm::Function&,
llvm::DominatorTree const&, llvm::PostDominatorTree const&,
llvm::LoopInfo const&, llvm::TargetTransformInfo const&)
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/DivergenceAnalysis.cpp:446:1
#14 0x0000000004c162c5
std::enable_if<!(std::is_array<llvm::GPUDivergenceAnalysis>::value),
std::unique_ptr<llvm::GPUDivergenceAnalysis,
std::default_delete<llvm::GPUDivergenceAnalysis> > >::type
llvm::make_unique<llvm::GPUDivergenceAnalysis, llvm::Function&,
llvm::DominatorTree&, llvm::PostDominatorTree&, llvm::LoopInfo&,
llvm::TargetTransformInfo&>(llvm::Function&, llvm::DominatorTree&,
llvm::PostDominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo&)
/home/jayfoad2/git/llvm-project/llvm/include/llvm/ADT/STLExtras.h:1406:10
#15 0x0000000004c14b15
llvm::LegacyDivergenceAnalysis::runOnFunction(llvm::Function&)
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/LegacyDivergenceAnalysis.cpp:331:13
#16 0x00000000055c114c
llvm::FPPassManager::runOnFunction(llvm::Function&)
/home/jayfoad2/git/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1648:23
#17 0x00000000055c15a2 llvm::FPPassManager::runOnModule(llvm::Module&)
/home/jayfoad2/git/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1685:16
#18 0x00000000055c1d34 (anonymous
namespace)::MPPassManager::runOnModule(llvm::Module&)
/home/jayfoad2/git/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1750:23
#19 0x00000000055c1848
llvm::legacy::PassManagerImpl::run(llvm::Module&)
/home/jayfoad2/git/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1863:16
#20 0x00000000055c22c1 llvm::legacy::PassManager::run(llvm::Module&)
/home/jayfoad2/git/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:1894:3
#21 0x0000000003209671 main
/home/jayfoad2/git/llvm-project/llvm/tools/opt/opt.cpp:893:3
#22 0x00007f56adc99b97 __libc_start_main
/build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:344:0
#23 0x00000000031c502a _start (/home/jayfoad2/llvm-debug/bin/opt+0x31c502a)
Aborted (core dumped)

But if I try the same thing with bugpoint I get:

$ ~/llvm-debug/bin/bugpoint -use-gpu-divergence-analysis -divergence stripped.ll
Read input file : 'stripped.ll'
*** All input ok
Running selected passes on program to test for crash: Success!
Initializing execution environment: Found lli: /home/jayfoad2/llvm-debug/bin/lli
Sorry, I can't automatically select a safe interpreter!

Exiting.

What does this mean? What is a "safe interpreter", and why does
bugpoint think it needs one in order to try to reduce the test case?

The documentation for bugpoint suggests that it will only try to use a
"safe backend" if none of the passes specified on the command line
crash.

Jay.

Jay Foad via llvm-dev <llvm-dev@lists.llvm.org> writes:

I tried to reduce the test case in
https://bugs.llvm.org/show_bug.cgi?id=42706. Here it is crashing opt:

$ ~/llvm-debug/bin/opt -use-gpu-divergence-analysis -divergence stripped.ll
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.

opt:
/home/jayfoad2/git/llvm-project/llvm/lib/Analysis/SyncDependenceAnalysis.cpp:312:
std::unique_ptr<ConstBlockSet>
llvm::DivergencePropagator::computeJoinPoints(const llvm::BasicBlock
&, SuccessorIterable, const llvm::Loop *, const llvm::BasicBlock *)
[SuccessorIterable = llvm::iterator_range<llvm::SuccIterator<const
llvm::Instruction, const llvm::BasicBlock> >]: Assertion
`HeaderDefBlock && "no definition in header of carrying loop"' failed.

...

Aborted (core dumped)

But if I try the same thing with bugpoint I get:

$ ~/llvm-debug/bin/bugpoint -use-gpu-divergence-analysis -divergence stripped.ll
Read input file : 'stripped.ll'
*** All input ok
Running selected passes on program to test for crash: Success!
Initializing execution environment: Found lli: /home/jayfoad2/llvm-debug/bin/lli
Sorry, I can't automatically select a safe interpreter!

Exiting.

What does this mean? What is a "safe interpreter", and why does
bugpoint think it needs one in order to try to reduce the test case?

Bugpoint's user interface is notoriously complex. I'm not sure why it's
going the safe interpreter route instead of reducing the crash, but I'd
recommend trying the custom scripts approach in this article for
reducing something like this:

    http://blog.llvm.org/2015/11/reduce-your-testcases-with-bugpoint-and.html

It avoids some of bugpoint's magic, so it tends to be easier to get what
you want.

IIRC, bugpoint tries to initialize the execution environment (i.e., using the JIT) before checking if the codegen phases crashes. So if you have a target that doesn't support JIT execution, you're stuck using custom scripts instead.

(Forgot to cc the list...)

Bugpoint's user interface is notoriously complex. I'm not sure why it's
going the safe interpreter route instead of reducing the crash, but I'd
recommend trying the custom scripts approach in this article for
reducing something like this:

    http://blog.llvm.org/2015/11/reduce-your-testcases-with-bugpoint-and.html

It avoids some of bugpoint's magic, so it tends to be easier to get what
you want.

Thanks! I got it working with:

$ cat script
~/llvm-debug/bin/opt -use-gpu-divergence-analysis -divergence
-disable-symbolication -o /dev/null "$@"

$ ~/llvm-debug/bin/bugpoint -compile-custom -compile-command=./script
stripped.bc

Jay.

Yeah but... it crashes in generic IR passes, so why would it get as
far as codegen?

Jay.

From: llvm-dev [mailto:llvm-dev-bounces@lists.llvm.org] On Behalf Of Justin
Bogner via llvm-dev
Sent: Monday, July 22, 2019 11:44
To: Jay Foad via llvm-dev <llvm-dev@lists.llvm.org>
Subject: Re: [llvm-dev] Fwd: bugpoint can't automatically select a safe
interpreter!

Bugpoint's user interface is notoriously complex. I'm not sure why it's going
the safe interpreter route instead of reducing the crash, but I'd recommend
trying the custom scripts approach in this article for reducing something like
this:

IIRC, bugpoint tries to initialize the execution environment (i.e., using the JIT) before checking if the codegen phases crashes. So if you have a target that doesn't support JIT execution, you're stuck using custom scripts instead.

bugpoint's defaults aren't good, unfortunately. You should just need to
use the -llc-safe flag, and that will avoid the "can't automatically
select a safe interpreter" error.

-Hal

You should just need to
use the -llc-safe flag, and that will avoid the "can't automatically
select a safe interpreter" error.

Yes, that works too, thanks. It wasn't at all obvious from reading the -help.

Jay.