Repository: rust
Issue: deeply-nested chain hangs with Item = u32
Labels: A-LLVM,T-compiler,C-bug,I-hang

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
pub fn foo() -> Box<Iterator<Item = u32>> {
    use std::iter::empty;

    Box::new(empty()
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty()) // 10th .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty())
        .chain(empty()) // 16th .chain(empty())
    )
}
```

This is adapted from the [deeply-nested](https://github.com/rust-lang/rustc-perf/blob/master/collector/benchmarks/deeply-nested/src/lib.rs) test, just changing `Item = ()` to `Item = u32`.

Building with `rustc +nightly --crate-type lib -Copt-level=2 src/lib.rs` seems to hang indefinitely.

I expected to see this happen: completion in a few seconds at most.

Instead, this happened: I'm still waiting...

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.44.0-nightly (537ccdf3a 2020-04-02)
binary: rustc
commit-hash: 537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae
commit-date: 2020-04-02
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0
```

Also happens on 1.42.0 and 1.43.0-beta.3.

Attaching rust-gdb, I see two busy LLVM threads:
<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
Thread 6 (Thread 0x7f70bd5ff700 (LWP 207946)):
#0  0x00007f70c72133db in llvm::DominatorTreeBase<llvm::BasicBlock, false>::dominates(llvm::BasicBlock const*, llvm::BasicBlock const*) const () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#1  0x00007f70c7e2298a in llvm::GVN::findLeader(llvm::BasicBlock const*, unsigned int) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#2  0x00007f70c7e23279 in llvm::GVN::processInstruction(llvm::Instruction*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#3  0x00007f70c7e24977 in llvm::GVN::processBlock(llvm::BasicBlock*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#4  0x00007f70c7e1aff0 in llvm::GVN::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::DominatorTree&, llvm::TargetLibraryInfo const&, llvm::AAResults&, llvm::MemoryDependenceResults*, llvm::LoopInfo*, llvm::OptimizationRemarkEmitter*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#5  0x00007f70c7e27098 in llvm::gvn::GVNLegacyPass::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#6  0x00007f70c727842f in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#7  0x00007f70c8233a78 in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#8  0x00007f70c7279030 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#9  0x00007f70c71e210a in LLVMRunPassManager () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#10 0x00007f70caa79b43 in rustc_codegen_llvm::back::write::optimize () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#11 0x00007f70caa3ef17 in rustc_codegen_ssa::back::write::execute_work_item () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#12 0x00007f70cab2680e in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#13 0x00007f70caa08eb5 in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#14 0x00007f70c9fe92ff in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#15 0x00007f70ca01c813 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#16 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:13
#17 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:80
#18 0x00007f70c9f534e2 in start_thread () from /lib64/libpthread.so.0
#19 0x00007f70c9e706d3 in clone () from /lib64/libc.so.6

Thread 5 (Thread 0x7f70be1ff700 (LWP 207945)):
#0  0x00007f70c7213354 in llvm::DominatorTreeBase<llvm::BasicBlock, false>::dominates(llvm::BasicBlock const*, llvm::BasicBlock const*) const () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#1  0x00007f70c7e2298a in llvm::GVN::findLeader(llvm::BasicBlock const*, unsigned int) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#2  0x00007f70c7e23279 in llvm::GVN::processInstruction(llvm::Instruction*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#3  0x00007f70c7e24977 in llvm::GVN::processBlock(llvm::BasicBlock*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#4  0x00007f70c7e1aff0 in llvm::GVN::runImpl(llvm::Function&, llvm::AssumptionCache&, llvm::DominatorTree&, llvm::TargetLibraryInfo const&, llvm::AAResults&, llvm::MemoryDependenceResults*, llvm::LoopInfo*, llvm::OptimizationRemarkEmitter*) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#5  0x00007f70c7e27098 in llvm::gvn::GVNLegacyPass::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#6  0x00007f70c727842f in llvm::FPPassManager::runOnFunction(llvm::Function&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#7  0x00007f70c8233a78 in (anonymous namespace)::CGPassManager::runOnModule(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#8  0x00007f70c7279030 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#9  0x00007f70c71e210a in LLVMRunPassManager () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-9-rust-1.44.0-nightly.so
#10 0x00007f70caa79b43 in rustc_codegen_llvm::back::write::optimize () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#11 0x00007f70caa3ef17 in rustc_codegen_ssa::back::write::execute_work_item () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#12 0x00007f70cab2680e in std::sys_common::backtrace::__rust_begin_short_backtrace () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#13 0x00007f70caa08eb5 in core::ops::function::FnOnce::call_once{{vtable-shim}} () from /home/jistone/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-ebfe476c9299964b.so
#14 0x00007f70c9fe92ff in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#15 0x00007f70ca01c813 in <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once () at /rustc/537ccdf3ac44c8c7a8d36cbdbe6fb224afabb7ae/src/liballoc/boxed.rs:1008
#16 std::sys_common::thread::start_thread () at src/libstd/sys_common/thread.rs:13
#17 std::sys::unix::thread::Thread::new::thread_start () at src/libstd/sys/unix/thread.rs:80
#18 0x00007f70c9f534e2 in start_thread () from /lib64/libpthread.so.0
#19 0x00007f70c9e706d3 in clone () from /lib64/libc.so.6
```

</p>
</details>