Repository: rust
Issue: [ER] Possible basic panic_bounds_check left after Vec::resize_with
Labels: A-LLVM,I-slow,C-enhancement,A-codegen,T-compiler,I-heavy

I don't understand this situation much. This code:
```rust
pub fn foo() -> Vec<usize> {
    let mut arr: Vec<usize> = vec![];
    arr.resize_with(100, || Default::default());
    for i in 0 .. 100 {
        arr[i] = i;
    }
    arr
}

pub fn foo2() -> Vec<usize> {
    let mut arr: Vec<usize> = vec![];
    arr.resize_with(100, || Default::default());
    arr[0] = 1;
    arr
}
```
With `rustc 1.47.0-nightly cfc572cae 2020-07-30` gives the asm:
```asm
foo:
        push    r15
        push    r14
        push    r12
        push    rbx
        push    rax
        mov     r14, rdi
        mov     qword ptr [rdi], 8
        vxorps  xmm0, xmm0, xmm0
        vmovups xmmword ptr [rdi + 8], xmm0
        mov     esi, 100
        call    alloc::vec::Vec<T>::reserve
        mov     r12, qword ptr [r14]
        mov     r15, qword ptr [r14 + 16]
        lea     rdi, [r12 + 8*r15]
        xor     ebx, ebx
        mov     edx, 792
        xor     esi, esi
        call    qword ptr [rip + memset@GOTPCREL]
        mov     qword ptr [r12 + 8*r15 + 792], 0
        add     r15, 100
        mov     qword ptr [r14 + 16], r15
.LBB1_1:
        cmp     r15, rbx
        je      .LBB1_8
        mov     qword ptr [r12 + 8*rbx], rbx
        lea     rax, [rbx + 1]
        cmp     rax, r15
        je      .LBB1_8
        mov     qword ptr [r12 + 8*rbx + 8], rax
        inc     rax
        cmp     rax, r15
        je      .LBB1_8
        mov     qword ptr [r12 + 8*rbx + 16], rax
        inc     rax
        cmp     rax, r15
        je      .LBB1_8
        mov     qword ptr [r12 + 8*rbx + 24], rax
        inc     rax
        cmp     rax, r15
        je      .LBB1_8
        mov     qword ptr [r12 + 8*rbx + 32], rax
        inc     rax
        mov     rbx, rax
        cmp     rax, 100
        jne     .LBB1_1
        mov     rax, r14
        add     rsp, 8
        pop     rbx
        pop     r12
        pop     r14
        pop     r15
        ret
.LBB1_8:
        lea     rdx, [rip + .L__unnamed_1]
        mov     rdi, r15
        mov     rsi, r15
        call    qword ptr [rip + core::panicking::panic_bounds_check@GOTPCREL]
        ud2


foo2:
        push    r15
        push    r14
        push    rbx
        mov     r15, rdi
        mov     qword ptr [rdi], 8
        vxorps  xmm0, xmm0, xmm0
        vmovups xmmword ptr [rdi + 8], xmm0
        mov     esi, 100
        call    alloc::vec::Vec<T>::reserve
        mov     r14, qword ptr [r15]
        mov     rbx, qword ptr [r15 + 16]
        lea     rdi, [r14 + 8*rbx]
        mov     edx, 792
        xor     esi, esi
        call    qword ptr [rip + memset@GOTPCREL]
        mov     qword ptr [r14 + 8*rbx + 792], 0
        add     rbx, 100
        mov     qword ptr [r15 + 16], rbx
        je      .LBB2_1
        mov     qword ptr [r14], 1
        mov     rax, r15
        pop     rbx
        pop     r14
        pop     r15
        ret
.LBB2_1:
        lea     rdx, [rip + .L__unnamed_2]
        xor     edi, edi
        xor     esi, esi
        call    qword ptr [rip + core::panicking::panic_bounds_check@GOTPCREL]
        ud2
```
That contains panic_bounds_check. If I compile only of those functions the panic_bounds_check go away.