Repository: rust
Issue: -Ctarget-cpu=skylake trashes ends_with_str performance
Labels: A-LLVM,I-slow,T-compiler,C-bug,A-target-feature

I was running these benchmarks:

```rust
#![feature(test)]

extern crate test;
use crate::test::black_box;
use crate::test::Bencher;

fn main() {
    println!("Hello, world!");
}

#[bench]
fn starts_with_char(b: &mut Bencher) {
    let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
    b.iter(|| {
        for _ in 0..1024 {
            black_box(text.starts_with('k'));
        }
    })
}

#[bench]
fn starts_with_str(b: &mut Bencher) {
    let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
    b.iter(|| {
        for _ in 0..1024 {
            black_box(text.starts_with("k"));
        }
    })
}

#[bench]
fn ends_with_char(b: &mut Bencher) {
    let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
    b.iter(|| {
        for _ in 0..1024 {
            black_box(text.ends_with('k'));
        }
    })
}

#[bench]
fn ends_with_str(b: &mut Bencher) {
    let text = black_box("kdjsfhlakfhlsghlkvcnljknfqiunvcijqenwodind");
    b.iter(|| {
        for _ in 0..1024 {
            black_box(text.ends_with("k"));
        }
    })
}

```


It turned out that I got a major performance drop with `-Ctarget-cpu=native` (`-Ctarget-cpu=skylake` in my case).

`RUSTFLAGS="-Ctarget-cpu=skylake" cargo bench`
````
running 4 tests
test ends_with_char   ... bench:         692 ns/iter (+/- 38)
test ends_with_str    ... bench:       1,033 ns/iter (+/- 23)
test starts_with_char ... bench:         356 ns/iter (+/- 44)
test starts_with_str  ... bench:         362 ns/iter (+/- 410)
````

`RUSTFLAGS="" cargo bench`

````
running 4 tests
test ends_with_char   ... bench:         468 ns/iter (+/- 21)
test ends_with_str    ... bench:         539 ns/iter (+/- 40)
test starts_with_char ... bench:         356 ns/iter (+/- 12)
test starts_with_str  ... bench:         693 ns/iter (+/- 44)
````

By generating code "optimized" for my machine, perf dropped from 539 ns/iter to  1,033 ns/iter  for `ends_with_str` :(



### Meta
cpu info:
```
processor	: 3
vendor_id	: GenuineIntel
cpu family	: 6
model		: 142
model name	: Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz
stepping	: 9
microcode	: 0xca
cpu MHz		: 591.388
cache size	: 3072 KB
physical id	: 0
siblings	: 4
core id		: 1
cpu cores	: 2
apicid		: 3
initial apicid	: 3
fpu		: yes
fpu_exception	: yes
cpuid level	: 22
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp md_clear flush_l1d
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit
bogomips	: 5401.81
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:
```


`rustc --version --verbose`:
```
rustc 1.43.0-nightly (abc3073c9 2020-02-26)
binary: rustc
commit-hash: abc3073c92df034636a823c5382ece2186d22b9e
commit-date: 2020-02-26
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
```