diff --git a/configure b/configure
index 505767cede552..4ce80a5e84919 100755
--- a/configure
+++ b/configure
@@ -517,7 +517,7 @@ case $CFG_CPUTYPE in
         CFG_OSTYPE="${CFG_OSTYPE}eabihf"
         ;;
 
-    aarch64)
+    aarch64 | arm64)
         CFG_CPUTYPE=aarch64
         ;;
 
diff --git a/mk/cfg/aarch64-unknown-freebsd.mk b/mk/cfg/aarch64-unknown-freebsd.mk
new file mode 100644
index 0000000000000..34aee77ae2107
--- /dev/null
+++ b/mk/cfg/aarch64-unknown-freebsd.mk
@@ -0,0 +1 @@
+# rustbuild-only target
diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py
index bc8341102421b..27255b6910093 100644
--- a/src/bootstrap/bootstrap.py
+++ b/src/bootstrap/bootstrap.py
@@ -379,6 +379,8 @@ def build_triple(self):
             ostype += 'eabihf'
         elif cputype == 'aarch64':
             cputype = 'aarch64'
+        elif cputype == 'arm64':
+            cputype = 'aarch64'
         elif cputype == 'mips':
             if sys.byteorder == 'big':
                 cputype = 'mips'
diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs
index 7e616c0ff27cf..cb7852995f3b1 100644
--- a/src/liballoc_jemalloc/build.rs
+++ b/src/liballoc_jemalloc/build.rs
@@ -41,6 +41,12 @@ fn main() {
         return;
     }
 
+    if target.contains("android") {
+        println!("cargo:rustc-link-lib=gcc");
+    } else if !target.contains("windows") && !target.contains("musl") {
+        println!("cargo:rustc-link-lib=pthread");
+    }
+
     if let Some(jemalloc) = env::var_os("JEMALLOC_OVERRIDE") {
         let jemalloc = PathBuf::from(jemalloc);
         println!("cargo:rustc-link-search=native={}",
@@ -66,11 +72,6 @@ fn main() {
         println!("cargo:rustc-link-lib=static=jemalloc_pic");
     }
     println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
-    if target.contains("android") {
-        println!("cargo:rustc-link-lib=gcc");
-    } else if !target.contains("windows") && !target.contains("musl") {
-        println!("cargo:rustc-link-lib=pthread");
-    }
     let src_dir = env::current_dir().unwrap().join("../jemalloc");
     rerun_if_changed_anything_in_dir(&src_dir);
     let timestamp = build_dir.join("rustbuild.timestamp");
diff --git a/src/libbacktrace/pecoff.c b/src/libbacktrace/pecoff.c
index 04e0bafb14981..2d6a9877219dc 100644
--- a/src/libbacktrace/pecoff.c
+++ b/src/libbacktrace/pecoff.c
@@ -607,7 +607,9 @@ coff_add (struct backtrace_state *state, int descriptor,
   //       against the upstream libbacktrace, that's what's going on.
   uint32_t str_size;
   off_t str_off;
-  struct backtrace_view syms_view;
+  // NOTE: upstream doesn't have `{0}`, this is a fix for Rust issue #39468.
+  //       If syms_view is not initialized, then `free(syms_view.base)` may segfault later.
+  struct backtrace_view syms_view = {0};
   off_t syms_off;
   size_t syms_size;
   int syms_view_valid;
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs
index 11f513ed798e0..2ea953df87357 100644
--- a/src/libcollections/slice.rs
+++ b/src/libcollections/slice.rs
@@ -98,7 +98,7 @@
 #![cfg_attr(test, allow(unused_imports, dead_code))]
 
 use alloc::boxed::Box;
-use core::cmp::Ordering::{self, Greater};
+use core::cmp::Ordering::{self, Less};
 use core::mem::size_of;
 use core::mem;
 use core::ptr;
@@ -1089,7 +1089,7 @@ impl<T> [T] {
     pub fn sort(&mut self)
         where T: Ord
     {
-        self.sort_by(|a, b| a.cmp(b))
+        merge_sort(self, |a, b| a.lt(b));
     }
 
     /// Sorts the slice using `f` to extract a key to compare elements by.
@@ -1119,7 +1119,7 @@ impl<T> [T] {
     pub fn sort_by_key<B, F>(&mut self, mut f: F)
         where F: FnMut(&T) -> B, B: Ord
     {
-        self.sort_by(|a, b| f(a).cmp(&f(b)))
+        merge_sort(self, |a, b| f(a).lt(&f(b)));
     }
 
     /// Sorts the slice using `compare` to compare elements.
@@ -1149,10 +1149,10 @@ impl<T> [T] {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
-    pub fn sort_by<F>(&mut self, compare: F)
+    pub fn sort_by<F>(&mut self, mut compare: F)
         where F: FnMut(&T, &T) -> Ordering
     {
-        merge_sort(self, compare)
+        merge_sort(self, |a, b| compare(a, b) == Less);
     }
 
     /// Copies the elements from `src` into `self`.
@@ -1355,10 +1355,10 @@ impl<T: Clone> ToOwned for [T] {
 /// Inserts `v[0]` into pre-sorted sequence `v[1..]` so that whole `v[..]` becomes sorted.
 ///
 /// This is the integral subroutine of insertion sort.
-fn insert_head<T, F>(v: &mut [T], compare: &mut F)
-    where F: FnMut(&T, &T) -> Ordering
+fn insert_head<T, F>(v: &mut [T], is_less: &mut F)
+    where F: FnMut(&T, &T) -> bool
 {
-    if v.len() >= 2 && compare(&v[0], &v[1]) == Greater {
+    if v.len() >= 2 && is_less(&v[1], &v[0]) {
         unsafe {
             // There are three ways to implement insertion here:
             //
@@ -1381,12 +1381,12 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
 
             // Intermediate state of the insertion process is always tracked by `hole`, which
             // serves two purposes:
-            // 1. Protects integrity of `v` from panics in `compare`.
+            // 1. Protects integrity of `v` from panics in `is_less`.
             // 2. Fills the remaining hole in `v` in the end.
             //
             // Panic safety:
             //
-            // If `compare` panics at any point during the process, `hole` will get dropped and
+            // If `is_less` panics at any point during the process, `hole` will get dropped and
             // fill the hole in `v` with `tmp`, thus ensuring that `v` still holds every object it
             // initially held exactly once.
             let mut hole = InsertionHole {
@@ -1396,7 +1396,7 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
             ptr::copy_nonoverlapping(&v[1], &mut v[0], 1);
 
             for i in 2..v.len() {
-                if compare(&tmp.value, &v[i]) != Greater {
+                if !is_less(&v[i], &tmp.value) {
                     break;
                 }
                 ptr::copy_nonoverlapping(&v[i], &mut v[i - 1], 1);
@@ -1432,8 +1432,8 @@ fn insert_head<T, F>(v: &mut [T], compare: &mut F)
 ///
 /// The two slices must be non-empty and `mid` must be in bounds. Buffer `buf` must be long enough
 /// to hold a copy of the shorter slice. Also, `T` must not be a zero-sized type.
-unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
-    where F: FnMut(&T, &T) -> Ordering
+unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, is_less: &mut F)
+    where F: FnMut(&T, &T) -> bool
 {
     let len = v.len();
     let v = v.as_mut_ptr();
@@ -1449,12 +1449,12 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
     // hole in `v`.
     //
     // Intermediate state of the process is always tracked by `hole`, which serves two purposes:
-    // 1. Protects integrity of `v` from panics in `compare`.
+    // 1. Protects integrity of `v` from panics in `is_less`.
     // 2. Fills the remaining hole in `v` if the longer run gets consumed first.
     //
     // Panic safety:
     //
-    // If `compare` panics at any point during the process, `hole` will get dropped and fill the
+    // If `is_less` panics at any point during the process, `hole` will get dropped and fill the
     // hole in `v` with the unconsumed range in `buf`, thus ensuring that `v` still holds every
     // object it initially held exactly once.
     let mut hole;
@@ -1476,7 +1476,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
         while *left < hole.end && right < v_end {
             // Consume the lesser side.
             // If equal, prefer the left run to maintain stability.
-            let to_copy = if compare(&**left, &*right) == Greater {
+            let to_copy = if is_less(&*right, &**left) {
                 get_and_increment(&mut right)
             } else {
                 get_and_increment(left)
@@ -1500,7 +1500,7 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
         while v < *left && buf < *right {
             // Consume the greater side.
             // If equal, prefer the right run to maintain stability.
-            let to_copy = if compare(&*left.offset(-1), &*right.offset(-1)) == Greater {
+            let to_copy = if is_less(&*right.offset(-1), &*left.offset(-1)) {
                 decrement_and_get(left)
             } else {
                 decrement_and_get(right)
@@ -1550,8 +1550,8 @@ unsafe fn merge<T, F>(v: &mut [T], mid: usize, buf: *mut T, compare: &mut F)
 /// 2. for every `i` in `2..runs.len()`: `runs[i - 2].len > runs[i - 1].len + runs[i].len`
 ///
 /// The invariants ensure that the total running time is `O(n log n)` worst-case.
-fn merge_sort<T, F>(v: &mut [T], mut compare: F)
-    where F: FnMut(&T, &T) -> Ordering
+fn merge_sort<T, F>(v: &mut [T], mut is_less: F)
+    where F: FnMut(&T, &T) -> bool
 {
     // Sorting has no meaningful behavior on zero-sized types.
     if size_of::<T>() == 0 {
@@ -1565,7 +1565,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
     //
     // Short runs are extended using insertion sort to span at least `min_run` elements, in order
     // to improve performance.
-    let (max_insertion, min_run) = if size_of::<T>() <= 16 {
+    let (max_insertion, min_run) = if size_of::<T>() <= 2 * mem::size_of::<usize>() {
         (64, 32)
     } else {
         (32, 16)
@@ -1577,7 +1577,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
     if len <= max_insertion {
         if len >= 2 {
             for i in (0..len-1).rev() {
-                insert_head(&mut v[i..], &mut compare);
+                insert_head(&mut v[i..], &mut is_less);
             }
         }
         return;
@@ -1585,7 +1585,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
 
     // Allocate a buffer to use as scratch memory. We keep the length 0 so we can keep in it
     // shallow copies of the contents of `v` without risking the dtors running on copies if
-    // `compare` panics. When merging two sorted runs, this buffer holds a copy of the shorter run,
+    // `is_less` panics. When merging two sorted runs, this buffer holds a copy of the shorter run,
     // which will always have length at most `len / 2`.
     let mut buf = Vec::with_capacity(len / 2);
 
@@ -1600,14 +1600,18 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
         let mut start = end - 1;
         if start > 0 {
             start -= 1;
-            if compare(&v[start], &v[start + 1]) == Greater {
-                while start > 0 && compare(&v[start - 1], &v[start]) == Greater {
-                    start -= 1;
-                }
-                v[start..end].reverse();
-            } else {
-                while start > 0 && compare(&v[start - 1], &v[start]) != Greater {
-                    start -= 1;
+            unsafe {
+                if is_less(v.get_unchecked(start + 1), v.get_unchecked(start)) {
+                    while start > 0 && is_less(v.get_unchecked(start),
+                                               v.get_unchecked(start - 1)) {
+                        start -= 1;
+                    }
+                    v[start..end].reverse();
+                } else {
+                    while start > 0 && !is_less(v.get_unchecked(start),
+                                                v.get_unchecked(start - 1)) {
+                        start -= 1;
+                    }
                 }
             }
         }
@@ -1616,7 +1620,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
         // merge sort on short sequences, so this significantly improves performance.
         while start > 0 && end - start < min_run {
             start -= 1;
-            insert_head(&mut v[start..end], &mut compare);
+            insert_head(&mut v[start..end], &mut is_less);
         }
 
         // Push this run onto the stack.
@@ -1632,7 +1636,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F)
             let right = runs[r];
             unsafe {
                 merge(&mut v[left.start .. right.start + right.len], left.len, buf.as_mut_ptr(),
-                      &mut compare);
+                      &mut is_less);
             }
             runs[r] = Run {
                 start: left.start,
diff --git a/src/libcollectionstest/slice.rs b/src/libcollectionstest/slice.rs
index 1b52214dee6ae..b9dec6be7b885 100644
--- a/src/libcollectionstest/slice.rs
+++ b/src/libcollectionstest/slice.rs
@@ -1429,18 +1429,15 @@ mod bench {
     fn sort_large_random_expensive(b: &mut Bencher) {
         let len = 10000;
         b.iter(|| {
+            let mut v = gen_random(len);
             let mut count = 0;
-            let cmp = move |a: &u64, b: &u64| {
+            v.sort_by(|a: &u64, b: &u64| {
                 count += 1;
                 if count % 1_000_000_000 == 0 {
                     panic!("should not happen");
                 }
                 (*a as f64).cos().partial_cmp(&(*b as f64).cos()).unwrap()
-            };
-
-            let mut v = gen_random(len);
-            v.sort_by(cmp);
-
+            });
             black_box(count);
         });
         b.bytes = len as u64 * mem::size_of::<u64>() as u64;
diff --git a/src/libcompiler_builtins/lib.rs b/src/libcompiler_builtins/lib.rs
index b2a615456aa59..482d70895ff89 100644
--- a/src/libcompiler_builtins/lib.rs
+++ b/src/libcompiler_builtins/lib.rs
@@ -544,8 +544,7 @@ pub mod reimpls {
         const MD1 : u32 = MANTISSA_DIGITS + 1;
         const MD2 : u32 = MANTISSA_DIGITS + 2;
 
-        // SNAP: replace this with !0u128
-        let negn :u128 = !0;
+        let negn = !0u128;
 
         if sd > MANTISSA_DIGITS {
             a = match sd {
@@ -579,8 +578,7 @@ pub mod reimpls {
         const MD1 : u32 = MANTISSA_DIGITS + 1;
         const MD2 : u32 = MANTISSA_DIGITS + 2;
 
-        // SNAP: replace this with !0u128
-        let negn :u128 = !0;
+        let negn = !0u128;
 
         if sd > MANTISSA_DIGITS {
             a = match sd {
@@ -652,17 +650,17 @@ pub mod reimpls {
         }
 
         #[export_name="__fixunssfti"]
-        pub extern "unadjusted" fn f32_as_u128(a: f32) -> u128 {
+        pub extern $unadj fn f32_as_u128(a: f32) -> u128 {
             float_as_unsigned!(a, f32, u128)
         }
 
         #[export_name="__fixdfti"]
-        pub extern "unadjusted" fn f64_as_i128(a: f64) -> i128 {
+        pub extern $unadj fn f64_as_i128(a: f64) -> i128 {
             float_as_signed!(a, f64, i128)
         }
 
         #[export_name="__fixsfti"]
-        pub extern "unadjusted" fn f32_as_i128(a: f32) -> i128 {
+        pub extern $unadj fn f32_as_i128(a: f32) -> i128 {
             float_as_signed!(a, f32, i128)
         }
 
diff --git a/src/libcore/Cargo.toml b/src/libcore/Cargo.toml
index e0dbc096cd0d9..4f7cd7b016d66 100644
--- a/src/libcore/Cargo.toml
+++ b/src/libcore/Cargo.toml
@@ -13,7 +13,6 @@ bench = false
 name = "coretest"
 path = "../libcoretest/lib.rs"
 
-# FIXME: need to extract benchmarks to a separate crate
-#[[bench]]
-#name = "coretest"
-#path = "../libcoretest/lib.rs"
+[[bench]]
+name = "corebench"
+path = "../libcore/bench/lib.rs"
diff --git a/src/libcore/bench/any.rs b/src/libcore/bench/any.rs
new file mode 100644
index 0000000000000..67e02cf9509b6
--- /dev/null
+++ b/src/libcore/bench/any.rs
@@ -0,0 +1,22 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use core::any::*;
+use test::{Bencher, black_box};
+
+#[bench]
+fn bench_downcast_ref(b: &mut Bencher) {
+    b.iter(|| {
+        let mut x = 0;
+        let mut y = &mut x as &mut Any;
+        black_box(&mut y);
+        black_box(y.downcast_ref::<isize>() == Some(&0));
+    });
+}
diff --git a/src/libcore/bench/hash/mod.rs b/src/libcore/bench/hash/mod.rs
new file mode 100644
index 0000000000000..55d9e3e091380
--- /dev/null
+++ b/src/libcore/bench/hash/mod.rs
@@ -0,0 +1,11 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod sip;
diff --git a/src/libcore/bench/hash/sip.rs b/src/libcore/bench/hash/sip.rs
new file mode 100644
index 0000000000000..3379c85bbec7d
--- /dev/null
+++ b/src/libcore/bench/hash/sip.rs
@@ -0,0 +1,151 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![allow(deprecated)]
+
+use core::hash::*;
+use test::{Bencher, black_box};
+
+fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
+    Hasher::write(&mut s, x);
+    s.finish()
+}
+
+fn hash_with<H: Hasher, T: Hash>(mut st: H, x: &T) -> u64 {
+    x.hash(&mut st);
+    st.finish()
+}
+
+fn hash<T: Hash>(x: &T) -> u64 {
+    hash_with(SipHasher::new(), x)
+}
+
+#[bench]
+fn bench_str_under_8_bytes(b: &mut Bencher) {
+    let s = "foo";
+    b.iter(|| {
+        assert_eq!(hash(&s), 16262950014981195938);
+    })
+}
+
+#[bench]
+fn bench_str_of_8_bytes(b: &mut Bencher) {
+    let s = "foobar78";
+    b.iter(|| {
+        assert_eq!(hash(&s), 4898293253460910787);
+    })
+}
+
+#[bench]
+fn bench_str_over_8_bytes(b: &mut Bencher) {
+    let s = "foobarbaz0";
+    b.iter(|| {
+        assert_eq!(hash(&s), 10581415515220175264);
+    })
+}
+
+#[bench]
+fn bench_long_str(b: &mut Bencher) {
+    let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
+incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
+exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
+irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
+pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
+officia deserunt mollit anim id est laborum.";
+    b.iter(|| {
+        assert_eq!(hash(&s), 17717065544121360093);
+    })
+}
+
+#[bench]
+fn bench_u32(b: &mut Bencher) {
+    let u = 162629500u32;
+    let u = black_box(u);
+    b.iter(|| {
+        hash(&u)
+    });
+    b.bytes = 8;
+}
+
+#[bench]
+fn bench_u32_keyed(b: &mut Bencher) {
+    let u = 162629500u32;
+    let u = black_box(u);
+    let k1 = black_box(0x1);
+    let k2 = black_box(0x2);
+    b.iter(|| {
+        hash_with(SipHasher::new_with_keys(k1, k2), &u)
+    });
+    b.bytes = 8;
+}
+
+#[bench]
+fn bench_u64(b: &mut Bencher) {
+    let u = 16262950014981195938u64;
+    let u = black_box(u);
+    b.iter(|| {
+        hash(&u)
+    });
+    b.bytes = 8;
+}
+
+#[bench]
+fn bench_bytes_4(b: &mut Bencher) {
+    let data = black_box([b' '; 4]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 4;
+}
+
+#[bench]
+fn bench_bytes_7(b: &mut Bencher) {
+    let data = black_box([b' '; 7]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 7;
+}
+
+#[bench]
+fn bench_bytes_8(b: &mut Bencher) {
+    let data = black_box([b' '; 8]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 8;
+}
+
+#[bench]
+fn bench_bytes_a_16(b: &mut Bencher) {
+    let data = black_box([b' '; 16]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 16;
+}
+
+#[bench]
+fn bench_bytes_b_32(b: &mut Bencher) {
+    let data = black_box([b' '; 32]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 32;
+}
+
+#[bench]
+fn bench_bytes_c_128(b: &mut Bencher) {
+    let data = black_box([b' '; 128]);
+    b.iter(|| {
+        hash_bytes(SipHasher::default(), &data)
+    });
+    b.bytes = 128;
+}
diff --git a/src/libcore/bench/iter.rs b/src/libcore/bench/iter.rs
new file mode 100644
index 0000000000000..93d38a5bc83bb
--- /dev/null
+++ b/src/libcore/bench/iter.rs
@@ -0,0 +1,101 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use core::iter::*;
+use test::{Bencher, black_box};
+
+#[bench]
+fn bench_rposition(b: &mut Bencher) {
+    let it: Vec<usize> = (0..300).collect();
+    b.iter(|| {
+        it.iter().rposition(|&x| x <= 150);
+    });
+}
+
+#[bench]
+fn bench_skip_while(b: &mut Bencher) {
+    b.iter(|| {
+        let it = 0..100;
+        let mut sum = 0;
+        it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
+    });
+}
+
+#[bench]
+fn bench_multiple_take(b: &mut Bencher) {
+    let mut it = (0..42).cycle();
+    b.iter(|| {
+        let n = it.next().unwrap();
+        for _ in 0..n {
+            it.clone().take(it.next().unwrap()).all(|_| true);
+        }
+    });
+}
+
+fn scatter(x: i32) -> i32 { (x * 31) % 127 }
+
+#[bench]
+fn bench_max_by_key(b: &mut Bencher) {
+    b.iter(|| {
+        let it = 0..100;
+        it.max_by_key(|&x| scatter(x))
+    })
+}
+
+// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
+#[bench]
+fn bench_max_by_key2(b: &mut Bencher) {
+    fn max_index_iter(array: &[i32]) -> usize {
+        array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0
+    }
+
+    let mut data = vec![0; 1638];
+    data[514] = 9999;
+
+    b.iter(|| max_index_iter(&data));
+}
+
+#[bench]
+fn bench_max(b: &mut Bencher) {
+    b.iter(|| {
+        let it = 0..100;
+        it.map(scatter).max()
+    })
+}
+
+pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
+    for (a, b) in ys.iter_mut().zip(xs) {
+        *a = *b;
+    }
+}
+
+pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
+    for (a, b) in ys.iter_mut().zip(xs) {
+        *a += *b;
+    }
+}
+
+#[bench]
+fn bench_zip_copy(b: &mut Bencher) {
+    let source = vec![0u8; 16 * 1024];
+    let mut dst = black_box(vec![0u8; 16 * 1024]);
+    b.iter(|| {
+        copy_zip(&source, &mut dst)
+    })
+}
+
+#[bench]
+fn bench_zip_add(b: &mut Bencher) {
+    let source = vec![1.; 16 * 1024];
+    let mut dst = vec![0.; 16 * 1024];
+    b.iter(|| {
+        add_zip(&source, &mut dst)
+    });
+}
diff --git a/src/libcore/bench/lib.rs b/src/libcore/bench/lib.rs
new file mode 100644
index 0000000000000..d2db329da7999
--- /dev/null
+++ b/src/libcore/bench/lib.rs
@@ -0,0 +1,25 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![deny(warnings)]
+
+#![feature(flt2dec)]
+#![feature(slice_patterns)]
+#![feature(test)]
+
+extern crate core;
+extern crate test;
+
+mod any;
+mod hash;
+mod iter;
+mod mem;
+mod num;
+mod ops;
diff --git a/src/libcore/bench/mem.rs b/src/libcore/bench/mem.rs
new file mode 100644
index 0000000000000..8e541d92a7f17
--- /dev/null
+++ b/src/libcore/bench/mem.rs
@@ -0,0 +1,70 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use test::Bencher;
+
+// FIXME #13642 (these benchmarks should be in another place)
+// Completely miscellaneous language-construct benchmarks.
+// Static/dynamic method dispatch
+
+struct Struct {
+    field: isize
+}
+
+trait Trait {
+    fn method(&self) -> isize;
+}
+
+impl Trait for Struct {
+    fn method(&self) -> isize {
+        self.field
+    }
+}
+
+#[bench]
+fn trait_vtable_method_call(b: &mut Bencher) {
+    let s = Struct { field: 10 };
+    let t = &s as &Trait;
+    b.iter(|| {
+        t.method()
+    });
+}
+
+#[bench]
+fn trait_static_method_call(b: &mut Bencher) {
+    let s = Struct { field: 10 };
+    b.iter(|| {
+        s.method()
+    });
+}
+
+// Overhead of various match forms
+
+#[bench]
+fn match_option_some(b: &mut Bencher) {
+    let x = Some(10);
+    b.iter(|| {
+        match x {
+            Some(y) => y,
+            None => 11
+        }
+    });
+}
+
+#[bench]
+fn match_vec_pattern(b: &mut Bencher) {
+    let x = [1,2,3,4,5,6];
+    b.iter(|| {
+        match x {
+            [1,2,3,..] => 10,
+            _ => 11,
+        }
+    });
+}
diff --git a/src/libcore/bench/num/dec2flt/mod.rs b/src/libcore/bench/num/dec2flt/mod.rs
new file mode 100644
index 0000000000000..562866e11777c
--- /dev/null
+++ b/src/libcore/bench/num/dec2flt/mod.rs
@@ -0,0 +1,68 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::f64;
+use test::Bencher;
+
+#[bench]
+fn bench_0(b: &mut Bencher) {
+    b.iter(|| "0.0".parse::<f64>());
+}
+
+#[bench]
+fn bench_42(b: &mut Bencher) {
+    b.iter(|| "42".parse::<f64>());
+}
+
+#[bench]
+fn bench_huge_int(b: &mut Bencher) {
+    // 2^128 - 1
+    b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
+}
+
+#[bench]
+fn bench_short_decimal(b: &mut Bencher) {
+    b.iter(|| "1234.5678".parse::<f64>());
+}
+
+#[bench]
+fn bench_pi_long(b: &mut Bencher) {
+    b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
+}
+
+#[bench]
+fn bench_pi_short(b: &mut Bencher) {
+    b.iter(|| "3.141592653589793".parse::<f64>())
+}
+
+#[bench]
+fn bench_1e150(b: &mut Bencher) {
+    b.iter(|| "1e150".parse::<f64>());
+}
+
+#[bench]
+fn bench_long_decimal_and_exp(b: &mut Bencher) {
+    b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
+}
+
+#[bench]
+fn bench_min_subnormal(b: &mut Bencher) {
+    b.iter(|| "5e-324".parse::<f64>());
+}
+
+#[bench]
+fn bench_min_normal(b: &mut Bencher) {
+    b.iter(|| "2.2250738585072014e-308".parse::<f64>());
+}
+
+#[bench]
+fn bench_max(b: &mut Bencher) {
+    b.iter(|| "1.7976931348623157e308".parse::<f64>());
+}
diff --git a/src/libcore/bench/num/flt2dec/mod.rs b/src/libcore/bench/num/flt2dec/mod.rs
new file mode 100644
index 0000000000000..1de2bf4921f58
--- /dev/null
+++ b/src/libcore/bench/num/flt2dec/mod.rs
@@ -0,0 +1,24 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod strategy {
+    mod dragon;
+    mod grisu;
+}
+
+use core::num::flt2dec::{decode, DecodableFloat, FullDecoded, Decoded};
+use core::num::flt2dec::MAX_SIG_DIGITS;
+
+pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
+    match decode(v).1 {
+        FullDecoded::Finite(decoded) => decoded,
+        full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
+    }
+}
diff --git a/src/libcore/bench/num/flt2dec/strategy/dragon.rs b/src/libcore/bench/num/flt2dec/strategy/dragon.rs
new file mode 100644
index 0000000000000..6824cf40ed2ae
--- /dev/null
+++ b/src/libcore/bench/num/flt2dec/strategy/dragon.rs
@@ -0,0 +1,70 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::{i16, f64};
+use super::super::*;
+use core::num::flt2dec::strategy::dragon::*;
+use test::Bencher;
+
+#[bench]
+fn bench_small_shortest(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; MAX_SIG_DIGITS];
+    b.iter(|| format_shortest(&decoded, &mut buf));
+}
+
+#[bench]
+fn bench_big_shortest(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; MAX_SIG_DIGITS];
+    b.iter(|| format_shortest(&decoded, &mut buf));
+}
+
+#[bench]
+fn bench_small_exact_3(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 3];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_3(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 3];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_small_exact_12(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 12];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_12(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 12];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_small_exact_inf(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 1024];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_inf(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 1024];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
diff --git a/src/libcore/bench/num/flt2dec/strategy/grisu.rs b/src/libcore/bench/num/flt2dec/strategy/grisu.rs
new file mode 100644
index 0000000000000..82e1a858fca9f
--- /dev/null
+++ b/src/libcore/bench/num/flt2dec/strategy/grisu.rs
@@ -0,0 +1,77 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::{i16, f64};
+use super::super::*;
+use core::num::flt2dec::strategy::grisu::*;
+use test::Bencher;
+
+pub fn decode_finite<T: DecodableFloat>(v: T) -> Decoded {
+    match decode(v).1 {
+        FullDecoded::Finite(decoded) => decoded,
+        full_decoded => panic!("expected finite, got {:?} instead", full_decoded)
+    }
+}
+
+#[bench]
+fn bench_small_shortest(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; MAX_SIG_DIGITS];
+    b.iter(|| format_shortest(&decoded, &mut buf));
+}
+
+#[bench]
+fn bench_big_shortest(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; MAX_SIG_DIGITS];
+    b.iter(|| format_shortest(&decoded, &mut buf));
+}
+
+#[bench]
+fn bench_small_exact_3(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 3];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_3(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 3];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_small_exact_12(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 12];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_12(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 12];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_small_exact_inf(b: &mut Bencher) {
+    let decoded = decode_finite(3.141592f64);
+    let mut buf = [0; 1024];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
+
+#[bench]
+fn bench_big_exact_inf(b: &mut Bencher) {
+    let decoded = decode_finite(f64::MAX);
+    let mut buf = [0; 1024];
+    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
+}
diff --git a/src/libcore/bench/num/mod.rs b/src/libcore/bench/num/mod.rs
new file mode 100644
index 0000000000000..55f0bdb57ec82
--- /dev/null
+++ b/src/libcore/bench/num/mod.rs
@@ -0,0 +1,12 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+mod flt2dec;
+mod dec2flt;
diff --git a/src/libcore/bench/ops.rs b/src/libcore/bench/ops.rs
new file mode 100644
index 0000000000000..7f36a4b0771aa
--- /dev/null
+++ b/src/libcore/bench/ops.rs
@@ -0,0 +1,30 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use core::ops::*;
+use test::Bencher;
+
+// Overhead of dtors
+
+struct HasDtor {
+    _x: isize
+}
+
+impl Drop for HasDtor {
+    fn drop(&mut self) {
+    }
+}
+
+#[bench]
+fn alloc_obj_with_dtor(b: &mut Bencher) {
+    b.iter(|| {
+        HasDtor { _x : 10 };
+    })
+}
diff --git a/src/libcoretest/any.rs b/src/libcoretest/any.rs
index a9fc8913182b3..2d3e81aa131ed 100644
--- a/src/libcoretest/any.rs
+++ b/src/libcoretest/any.rs
@@ -7,9 +7,8 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
+
 use core::any::*;
-use test::Bencher;
-use test;
 
 #[derive(PartialEq, Debug)]
 struct Test;
@@ -124,13 +123,3 @@ fn any_unsized() {
     fn is_any<T: Any + ?Sized>() {}
     is_any::<[i32]>();
 }
-
-#[bench]
-fn bench_downcast_ref(b: &mut Bencher) {
-    b.iter(|| {
-        let mut x = 0;
-        let mut y = &mut x as &mut Any;
-        test::black_box(&mut y);
-        test::black_box(y.downcast_ref::<isize>() == Some(&0));
-    });
-}
diff --git a/src/libcoretest/hash/sip.rs b/src/libcoretest/hash/sip.rs
index fa3bfdea42df8..4a9657e03404a 100644
--- a/src/libcoretest/hash/sip.rs
+++ b/src/libcoretest/hash/sip.rs
@@ -10,8 +10,6 @@
 
 #![allow(deprecated)]
 
-use test::{Bencher, black_box};
-
 use core::hash::{Hash, Hasher};
 use core::hash::{SipHasher, SipHasher13, SipHasher24};
 use core::{slice, mem};
@@ -58,11 +56,6 @@ fn hash<T: Hash>(x: &T) -> u64 {
     hash_with(SipHasher::new(), x)
 }
 
-fn hash_bytes<H: Hasher>(mut s: H, x: &[u8]) -> u64 {
-    Hasher::write(&mut s, x);
-    s.finish()
-}
-
 #[test]
 #[allow(unused_must_use)]
 fn test_siphash_1_3() {
@@ -347,126 +340,3 @@ fn test_write_short_works() {
     h2.write(&[0xFFu8, 0x01u8]);
     assert_eq!(h1.finish(), h2.finish());
 }
-
-#[bench]
-fn bench_str_under_8_bytes(b: &mut Bencher) {
-    let s = "foo";
-    b.iter(|| {
-        assert_eq!(hash(&s), 16262950014981195938);
-    })
-}
-
-#[bench]
-fn bench_str_of_8_bytes(b: &mut Bencher) {
-    let s = "foobar78";
-    b.iter(|| {
-        assert_eq!(hash(&s), 4898293253460910787);
-    })
-}
-
-#[bench]
-fn bench_str_over_8_bytes(b: &mut Bencher) {
-    let s = "foobarbaz0";
-    b.iter(|| {
-        assert_eq!(hash(&s), 10581415515220175264);
-    })
-}
-
-#[bench]
-fn bench_long_str(b: &mut Bencher) {
-    let s = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor \
-incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud \
-exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute \
-irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
-pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui \
-officia deserunt mollit anim id est laborum.";
-    b.iter(|| {
-        assert_eq!(hash(&s), 17717065544121360093);
-    })
-}
-
-#[bench]
-fn bench_u32(b: &mut Bencher) {
-    let u = 162629500u32;
-    let u = black_box(u);
-    b.iter(|| {
-        hash(&u)
-    });
-    b.bytes = 8;
-}
-
-#[bench]
-fn bench_u32_keyed(b: &mut Bencher) {
-    let u = 162629500u32;
-    let u = black_box(u);
-    let k1 = black_box(0x1);
-    let k2 = black_box(0x2);
-    b.iter(|| {
-        hash_with(SipHasher::new_with_keys(k1, k2), &u)
-    });
-    b.bytes = 8;
-}
-
-#[bench]
-fn bench_u64(b: &mut Bencher) {
-    let u = 16262950014981195938u64;
-    let u = black_box(u);
-    b.iter(|| {
-        hash(&u)
-    });
-    b.bytes = 8;
-}
-
-#[bench]
-fn bench_bytes_4(b: &mut Bencher) {
-    let data = black_box([b' '; 4]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 4;
-}
-
-#[bench]
-fn bench_bytes_7(b: &mut Bencher) {
-    let data = black_box([b' '; 7]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 7;
-}
-
-#[bench]
-fn bench_bytes_8(b: &mut Bencher) {
-    let data = black_box([b' '; 8]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 8;
-}
-
-#[bench]
-fn bench_bytes_a_16(b: &mut Bencher) {
-    let data = black_box([b' '; 16]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 16;
-}
-
-#[bench]
-fn bench_bytes_b_32(b: &mut Bencher) {
-    let data = black_box([b' '; 32]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 32;
-}
-
-#[bench]
-fn bench_bytes_c_128(b: &mut Bencher) {
-    let data = black_box([b' '; 128]);
-    b.iter(|| {
-        hash_bytes(SipHasher::default(), &data)
-    });
-    b.bytes = 128;
-}
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs
index c7833dbd15629..08442f9bcbff5 100644
--- a/src/libcoretest/iter.rs
+++ b/src/libcoretest/iter.rs
@@ -12,9 +12,6 @@ use core::iter::*;
 use core::{i8, i16, isize};
 use core::usize;
 
-use test::Bencher;
-use test::black_box;
-
 #[test]
 fn test_lt() {
     let empty: [isize; 0] = [];
@@ -1085,91 +1082,3 @@ fn test_chain_fold() {
     assert_eq!(&[2, 3, 1, 2, 0], &result[..]);
 }
 
-#[bench]
-fn bench_rposition(b: &mut Bencher) {
-    let it: Vec<usize> = (0..300).collect();
-    b.iter(|| {
-        it.iter().rposition(|&x| x <= 150);
-    });
-}
-
-#[bench]
-fn bench_skip_while(b: &mut Bencher) {
-    b.iter(|| {
-        let it = 0..100;
-        let mut sum = 0;
-        it.skip_while(|&x| { sum += x; sum < 4000 }).all(|_| true);
-    });
-}
-
-#[bench]
-fn bench_multiple_take(b: &mut Bencher) {
-    let mut it = (0..42).cycle();
-    b.iter(|| {
-        let n = it.next().unwrap();
-        for _ in 0..n {
-            it.clone().take(it.next().unwrap()).all(|_| true);
-        }
-    });
-}
-
-fn scatter(x: i32) -> i32 { (x * 31) % 127 }
-
-#[bench]
-fn bench_max_by_key(b: &mut Bencher) {
-    b.iter(|| {
-        let it = 0..100;
-        it.max_by_key(|&x| scatter(x))
-    })
-}
-
-// http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
-#[bench]
-fn bench_max_by_key2(b: &mut Bencher) {
-    fn max_index_iter(array: &[i32]) -> usize {
-        array.iter().enumerate().max_by_key(|&(_, item)| item).unwrap().0
-    }
-
-    let mut data = vec![0; 1638];
-    data[514] = 9999;
-
-    b.iter(|| max_index_iter(&data));
-}
-
-#[bench]
-fn bench_max(b: &mut Bencher) {
-    b.iter(|| {
-        let it = 0..100;
-        it.map(scatter).max()
-    })
-}
-
-pub fn copy_zip(xs: &[u8], ys: &mut [u8]) {
-    for (a, b) in ys.iter_mut().zip(xs) {
-        *a = *b;
-    }
-}
-
-pub fn add_zip(xs: &[f32], ys: &mut [f32]) {
-    for (a, b) in ys.iter_mut().zip(xs) {
-        *a += *b;
-    }
-}
-
-#[bench]
-fn bench_zip_copy(b: &mut Bencher) {
-    let source = vec![0u8; 16 * 1024];
-    let mut dst = black_box(vec![0u8; 16 * 1024]);
-    b.iter(|| {
-        copy_zip(&source, &mut dst)
-    })
-}
-
-#[bench]
-fn bench_zip_add(b: &mut Bencher) {
-    let source = vec![1.; 16 * 1024];
-    let mut dst = vec![0.; 16 * 1024];
-    b.iter(|| {
-        add_zip(&source, &mut dst)
-    });
-}
diff --git a/src/libcoretest/mem.rs b/src/libcoretest/mem.rs
index 01bafe49a7acd..86e59c736ba4a 100644
--- a/src/libcoretest/mem.rs
+++ b/src/libcoretest/mem.rs
@@ -7,8 +7,8 @@
 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
+
 use core::mem::*;
-use test::Bencher;
 
 #[test]
 fn size_of_basic() {
@@ -121,61 +121,3 @@ fn test_transmute() {
     }
 }
 
-// FIXME #13642 (these benchmarks should be in another place)
-/// Completely miscellaneous language-construct benchmarks.
-// Static/dynamic method dispatch
-
-struct Struct {
-    field: isize
-}
-
-trait Trait {
-    fn method(&self) -> isize;
-}
-
-impl Trait for Struct {
-    fn method(&self) -> isize {
-        self.field
-    }
-}
-
-#[bench]
-fn trait_vtable_method_call(b: &mut Bencher) {
-    let s = Struct { field: 10 };
-    let t = &s as &Trait;
-    b.iter(|| {
-        t.method()
-    });
-}
-
-#[bench]
-fn trait_static_method_call(b: &mut Bencher) {
-    let s = Struct { field: 10 };
-    b.iter(|| {
-        s.method()
-    });
-}
-
-// Overhead of various match forms
-
-#[bench]
-fn match_option_some(b: &mut Bencher) {
-    let x = Some(10);
-    b.iter(|| {
-        match x {
-            Some(y) => y,
-            None => 11
-        }
-    });
-}
-
-#[bench]
-fn match_vec_pattern(b: &mut Bencher) {
-    let x = [1,2,3,4,5,6];
-    b.iter(|| {
-        match x {
-            [1,2,3,..] => 10,
-            _ => 11,
-        }
-    });
-}
diff --git a/src/libcoretest/num/dec2flt/mod.rs b/src/libcoretest/num/dec2flt/mod.rs
index fe6f52406fbc8..5d546c643e7ee 100644
--- a/src/libcoretest/num/dec2flt/mod.rs
+++ b/src/libcoretest/num/dec2flt/mod.rs
@@ -11,7 +11,6 @@
 #![allow(overflowing_literals)]
 
 use std::{i64, f32, f64};
-use test;
 
 mod parse;
 mod rawfp;
@@ -144,59 +143,3 @@ fn borderline_overflow() {
     // It makes no sense to enshrine that in a test, the important part is that it doesn't panic.
     let _ = s.parse::<f64>();
 }
-
-#[bench]
-fn bench_0(b: &mut test::Bencher) {
-    b.iter(|| "0.0".parse::<f64>());
-}
-
-#[bench]
-fn bench_42(b: &mut test::Bencher) {
-    b.iter(|| "42".parse::<f64>());
-}
-
-#[bench]
-fn bench_huge_int(b: &mut test::Bencher) {
-    // 2^128 - 1
-    b.iter(|| "170141183460469231731687303715884105727".parse::<f64>());
-}
-
-#[bench]
-fn bench_short_decimal(b: &mut test::Bencher) {
-    b.iter(|| "1234.5678".parse::<f64>());
-}
-
-#[bench]
-fn bench_pi_long(b: &mut test::Bencher) {
-    b.iter(|| "3.14159265358979323846264338327950288".parse::<f64>());
-}
-
-#[bench]
-fn bench_pi_short(b: &mut test::Bencher) {
-    b.iter(|| "3.141592653589793".parse::<f64>())
-}
-
-#[bench]
-fn bench_1e150(b: &mut test::Bencher) {
-    b.iter(|| "1e150".parse::<f64>());
-}
-
-#[bench]
-fn bench_long_decimal_and_exp(b: &mut test::Bencher) {
-    b.iter(|| "727501488517303786137132964064381141071e-123".parse::<f64>());
-}
-
-#[bench]
-fn bench_min_subnormal(b: &mut test::Bencher) {
-    b.iter(|| "5e-324".parse::<f64>());
-}
-
-#[bench]
-fn bench_min_normal(b: &mut test::Bencher) {
-    b.iter(|| "2.2250738585072014e-308".parse::<f64>());
-}
-
-#[bench]
-fn bench_max(b: &mut test::Bencher) {
-    b.iter(|| "1.7976931348623157e308".parse::<f64>());
-}
diff --git a/src/libcoretest/num/flt2dec/strategy/dragon.rs b/src/libcoretest/num/flt2dec/strategy/dragon.rs
index 08c2cd0a7326f..4edb0f3df60c4 100644
--- a/src/libcoretest/num/flt2dec/strategy/dragon.rs
+++ b/src/libcoretest/num/flt2dec/strategy/dragon.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use std::prelude::v1::*;
-use std::{i16, f64};
 use super::super::*;
 use core::num::bignum::Big32x40 as Big;
 use core::num::flt2dec::strategy::dragon::*;
@@ -53,62 +52,6 @@ fn exact_sanity_test() {
     f32_exact_sanity_test(format_exact);
 }
 
-#[bench]
-fn bench_small_shortest(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; MAX_SIG_DIGITS];
-    b.iter(|| format_shortest(&decoded, &mut buf));
-}
-
-#[bench]
-fn bench_big_shortest(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; MAX_SIG_DIGITS];
-    b.iter(|| format_shortest(&decoded, &mut buf));
-}
-
-#[bench]
-fn bench_small_exact_3(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 3];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_3(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 3];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_small_exact_12(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 12];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_12(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 12];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_small_exact_inf(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 1024];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_inf(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 1024];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
 #[test]
 fn test_to_shortest_str() {
     to_shortest_str_test(format_shortest);
diff --git a/src/libcoretest/num/flt2dec/strategy/grisu.rs b/src/libcoretest/num/flt2dec/strategy/grisu.rs
index 311bd252353c7..79e66ee669e14 100644
--- a/src/libcoretest/num/flt2dec/strategy/grisu.rs
+++ b/src/libcoretest/num/flt2dec/strategy/grisu.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::{i16, f64};
+use std::i16;
 use super::super::*;
 use core::num::flt2dec::strategy::grisu::*;
 
@@ -102,62 +102,6 @@ fn exact_f64_random_equivalence_test() {
     }
 }
 
-#[bench]
-fn bench_small_shortest(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; MAX_SIG_DIGITS];
-    b.iter(|| format_shortest(&decoded, &mut buf));
-}
-
-#[bench]
-fn bench_big_shortest(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; MAX_SIG_DIGITS];
-    b.iter(|| format_shortest(&decoded, &mut buf));
-}
-
-#[bench]
-fn bench_small_exact_3(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 3];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_3(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 3];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_small_exact_12(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 12];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_12(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 12];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_small_exact_inf(b: &mut Bencher) {
-    let decoded = decode_finite(3.141592f64);
-    let mut buf = [0; 1024];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
-#[bench]
-fn bench_big_exact_inf(b: &mut Bencher) {
-    let decoded = decode_finite(f64::MAX);
-    let mut buf = [0; 1024];
-    b.iter(|| format_exact(&decoded, &mut buf, i16::MIN));
-}
-
 #[test]
 fn test_to_shortest_str() {
     to_shortest_str_test(format_shortest);
diff --git a/src/libcoretest/ops.rs b/src/libcoretest/ops.rs
index 33674a3abd870..1c6c13b0d02e8 100644
--- a/src/libcoretest/ops.rs
+++ b/src/libcoretest/ops.rs
@@ -8,27 +8,8 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use test::Bencher;
 use core::ops::{Range, RangeFull, RangeFrom, RangeTo};
 
-// Overhead of dtors
-
-struct HasDtor {
-    _x: isize
-}
-
-impl Drop for HasDtor {
-    fn drop(&mut self) {
-    }
-}
-
-#[bench]
-fn alloc_obj_with_dtor(b: &mut Bencher) {
-    b.iter(|| {
-        HasDtor { _x : 10 };
-    })
-}
-
 // Test the Range structs without the syntactic sugar.
 
 #[test]
diff --git a/src/librustc/util/fs.rs b/src/librustc/util/fs.rs
index c290d8f893e9e..3b4b3998c5745 100644
--- a/src/librustc/util/fs.rs
+++ b/src/librustc/util/fs.rs
@@ -31,7 +31,7 @@ use std::io;
 //   https://github.com/rust-lang/rust/issues/25505#issuecomment-102876737
 pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
     if !cfg!(windows) {
-        return p.to_path_buf()
+        return p.to_path_buf();
     }
     let mut components = p.components();
     let prefix = match components.next() {
@@ -58,7 +58,7 @@ pub fn fix_windows_verbatim_for_gcc(p: &Path) -> PathBuf {
 
 pub enum LinkOrCopy {
     Link,
-    Copy
+    Copy,
 }
 
 /// Copy `p` into `q`, preferring to use hard-linking if possible. If
@@ -76,7 +76,35 @@ pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<Li
         Err(_) => {
             match fs::copy(p, q) {
                 Ok(_) => Ok(LinkOrCopy::Copy),
-                Err(e) => Err(e)
+                Err(e) => Err(e),
+            }
+        }
+    }
+}
+
+#[derive(Debug)]
+pub enum RenameOrCopyRemove {
+    Rename,
+    CopyRemove,
+}
+
+/// Rename `p` into `q`, preferring to use `rename` if possible.
+/// If `rename` fails (rename may fail for reasons such as crossing
+/// filesystem), fallback to copy & remove
+pub fn rename_or_copy_remove<P: AsRef<Path>, Q: AsRef<Path>>(p: P,
+                                                             q: Q)
+                                                             -> io::Result<RenameOrCopyRemove> {
+    let p = p.as_ref();
+    let q = q.as_ref();
+    match fs::rename(p, q) {
+        Ok(()) => Ok(RenameOrCopyRemove::Rename),
+        Err(_) => {
+            match fs::copy(p, q) {
+                Ok(_) => {
+                    fs::remove_file(p)?;
+                    Ok(RenameOrCopyRemove::CopyRemove)
+                }
+                Err(e) => Err(e),
             }
         }
     }
@@ -93,8 +121,7 @@ pub fn create_dir_racy(path: &Path) -> io::Result<()> {
     }
     match path.parent() {
         Some(p) => try!(create_dir_racy(p)),
-        None => return Err(io::Error::new(io::ErrorKind::Other,
-                                          "failed to create whole tree")),
+        None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
     }
     match fs::create_dir(path) {
         Ok(()) => Ok(()),
diff --git a/src/librustc_back/target/aarch64_unknown_freebsd.rs b/src/librustc_back/target/aarch64_unknown_freebsd.rs
new file mode 100644
index 0000000000000..3c5d6308ee6ba
--- /dev/null
+++ b/src/librustc_back/target/aarch64_unknown_freebsd.rs
@@ -0,0 +1,34 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use target::{Target, TargetOptions, TargetResult};
+
+pub fn target() -> TargetResult {
+    let mut base = super::freebsd_base::opts();
+    base.max_atomic_width = Some(128);
+
+    // see #36994
+    base.exe_allocation_crate = "alloc_system".to_string();
+
+    Ok(Target {
+        llvm_target: "aarch64-unknown-freebsd".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
+        arch: "aarch64".to_string(),
+        target_os: "freebsd".to_string(),
+        target_env: "".to_string(),
+        target_vendor: "unknown".to_string(),
+        options: TargetOptions {
+            abi_blacklist: super::arm_base::abi_blacklist(),
+            .. base
+        },
+    })
+}
diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs
index d2b76b1d55a98..9e232bc7e1f2f 100644
--- a/src/librustc_back/target/mod.rs
+++ b/src/librustc_back/target/mod.rs
@@ -165,6 +165,7 @@ supported_targets! {
     ("armv7-linux-androideabi", armv7_linux_androideabi),
     ("aarch64-linux-android", aarch64_linux_android),
 
+    ("aarch64-unknown-freebsd", aarch64_unknown_freebsd),
     ("i686-unknown-freebsd", i686_unknown_freebsd),
     ("x86_64-unknown-freebsd", x86_64_unknown_freebsd),
 
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs
index e2e76cdfb6ebd..af4f63a05613e 100644
--- a/src/librustc_const_eval/eval.rs
+++ b/src/librustc_const_eval/eval.rs
@@ -482,12 +482,9 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
                 (&LitKind::Int(I64_OVERFLOW, Signed(IntTy::I64)), _) => {
                     return Ok(Integral(I64(i64::min_value())))
                 },
-                (&LitKind::Int(n, _), Some(&ty::TyInt(IntTy::I128))) |
-                (&LitKind::Int(n, Signed(IntTy::I128)), _) => {
-                    // SNAP: replace n in pattern with I128_OVERFLOW and remove this if.
-                    if n == I128_OVERFLOW {
-                        return Ok(Integral(I128(i128::min_value())))
-                    }
+                (&LitKind::Int(I128_OVERFLOW, _), Some(&ty::TyInt(IntTy::I128))) |
+                (&LitKind::Int(I128_OVERFLOW, Signed(IntTy::I128)), _) => {
+                    return Ok(Integral(I128(i128::min_value())))
                 },
                 (&LitKind::Int(n, _), Some(&ty::TyInt(IntTy::Is))) |
                 (&LitKind::Int(n, Signed(IntTy::Is)), _) => {
diff --git a/src/librustc_const_math/int.rs b/src/librustc_const_math/int.rs
index 3618bfa20811f..17714f2fb2d6c 100644
--- a/src/librustc_const_math/int.rs
+++ b/src/librustc_const_math/int.rs
@@ -155,13 +155,11 @@ impl ConstInt {
             (InferSigned(a @ 0...ibounds::U8MAX), U8(_)) => U8(a as u8),
             (InferSigned(a @ 0...ibounds::U16MAX), U16(_)) => U16(a as u16),
             (InferSigned(a @ 0...ibounds::U32MAX), U32(_)) => U32(a as u32),
-            // SNAP: replace with U64MAX
-            (InferSigned(a @ 0...ibounds::I64MAX), U64(_)) => U64(a as u64),
+            (InferSigned(a @ 0...ibounds::U64MAX), U64(_)) => U64(a as u64),
             (InferSigned(a @ 0...ibounds::I128MAX), U128(_)) => U128(a as u128),
             (InferSigned(a @ 0...ibounds::U16MAX), Usize(Us16(_))) => Usize(Us16(a as u16)),
             (InferSigned(a @ 0...ibounds::U32MAX), Usize(Us32(_))) => Usize(Us32(a as u32)),
-            // SNAP: replace with U64MAX
-            (InferSigned(a @ 0...ibounds::I64MAX), Usize(Us64(_))) => Usize(Us64(a as u64)),
+            (InferSigned(a @ 0...ibounds::U64MAX), Usize(Us64(_))) => Usize(Us64(a as u64)),
             (InferSigned(_), _) => return Err(ConstMathErr::NotInRange),
             _ => self, // already known types
         };
diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs
index a04a5b106b8f1..33bf4d5276adf 100644
--- a/src/librustc_driver/driver.rs
+++ b/src/librustc_driver/driver.rs
@@ -22,6 +22,7 @@ use rustc::middle::privacy::AccessLevels;
 use rustc::ty::{self, TyCtxt, Resolutions, GlobalArenas};
 use rustc::util::common::time;
 use rustc::util::nodemap::{NodeSet, NodeMap};
+use rustc::util::fs::rename_or_copy_remove;
 use rustc_borrowck as borrowck;
 use rustc_incremental::{self, IncrementalHashesMap};
 use rustc_incremental::ich::Fingerprint;
@@ -1084,10 +1085,9 @@ pub fn phase_5_run_llvm_passes(sess: &Session,
         // are going to build an executable
         if sess.opts.output_types.contains_key(&OutputType::Exe) {
             let f = outputs.path(OutputType::Object);
-            fs::copy(&f,
+            rename_or_copy_remove(&f,
                      f.with_file_name(format!("{}.0.o",
                                               f.file_stem().unwrap().to_string_lossy()))).unwrap();
-            fs::remove_file(f).unwrap();
         }
 
         // Remove assembly source, unless --save-temps was specified
diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs
index 58b2017ceb66e..8510b9f523cb5 100644
--- a/src/librustc_llvm/ffi.rs
+++ b/src/librustc_llvm/ffi.rs
@@ -8,6 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+// FIXME: Rename 'DIGlobalVariable' to 'DIGlobalVariableExpression'
+// once support for LLVM 3.9 is dropped.
+//
+// This method was changed in this LLVM patch:
+// https://reviews.llvm.org/D26769
+
 use debuginfo::{DIBuilderRef, DIDescriptor, DIFile, DILexicalBlock, DISubprogram, DIType,
                 DIBasicType, DIDerivedType, DICompositeType, DIScope, DIVariable,
                 DIGlobalVariable, DIArray, DISubrange, DITemplateTypeParameter, DIEnumerator,
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs
index 725b0e06e3088..64100ed4191cc 100644
--- a/src/librustc_trans/common.rs
+++ b/src/librustc_trans/common.rs
@@ -229,15 +229,10 @@ pub fn C_integral(t: Type, u: u64, sign_extend: bool) -> ValueRef {
     }
 }
 
-pub fn C_big_integral(t: Type, u: u128, sign_extend: bool) -> ValueRef {
-    if ::std::mem::size_of::<u128>() == 16 {
-        unsafe {
-            let words = [u as u64, u.wrapping_shr(64) as u64];
-            llvm::LLVMConstIntOfArbitraryPrecision(t.to_ref(), 2, words.as_ptr())
-        }
-    } else {
-        // SNAP: remove after snapshot
-        C_integral(t, u as u64, sign_extend)
+pub fn C_big_integral(t: Type, u: u128) -> ValueRef {
+    unsafe {
+        let words = [u as u64, u.wrapping_shr(64) as u64];
+        llvm::LLVMConstIntOfArbitraryPrecision(t.to_ref(), 2, words.as_ptr())
     }
 }
 
diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs
index c8a680d25195a..f92faaa0508a6 100644
--- a/src/librustc_trans/mir/constant.rs
+++ b/src/librustc_trans/mir/constant.rs
@@ -75,7 +75,7 @@ impl<'tcx> Const<'tcx> {
             ConstVal::Integral(I16(v)) => C_integral(Type::i16(ccx), v as u64, true),
             ConstVal::Integral(I32(v)) => C_integral(Type::i32(ccx), v as u64, true),
             ConstVal::Integral(I64(v)) => C_integral(Type::i64(ccx), v as u64, true),
-            ConstVal::Integral(I128(v)) => C_big_integral(Type::i128(ccx), v as u128, true),
+            ConstVal::Integral(I128(v)) => C_big_integral(Type::i128(ccx), v as u128),
             ConstVal::Integral(Isize(v)) => {
                 let i = v.as_i64(ccx.tcx().sess.target.int_type);
                 C_integral(Type::int(ccx), i as u64, true)
@@ -84,7 +84,7 @@ impl<'tcx> Const<'tcx> {
             ConstVal::Integral(U16(v)) => C_integral(Type::i16(ccx), v as u64, false),
             ConstVal::Integral(U32(v)) => C_integral(Type::i32(ccx), v as u64, false),
             ConstVal::Integral(U64(v)) => C_integral(Type::i64(ccx), v, false),
-            ConstVal::Integral(U128(v)) => C_big_integral(Type::i128(ccx), v, false),
+            ConstVal::Integral(U128(v)) => C_big_integral(Type::i128(ccx), v),
             ConstVal::Integral(Usize(v)) => {
                 let u = v.as_u64(ccx.tcx().sess.target.uint_type);
                 C_integral(Type::int(ccx), u, false)
diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs
index dcab30aad8385..c690fd467ee41 100644
--- a/src/libstd/sys/unix/fd.rs
+++ b/src/libstd/sys/unix/fd.rs
@@ -144,11 +144,24 @@ impl FileDesc {
     pub fn set_cloexec(&self) -> io::Result<()> {
         unsafe {
             let previous = cvt(libc::fcntl(self.fd, libc::F_GETFD))?;
-            cvt(libc::fcntl(self.fd, libc::F_SETFD, previous | libc::FD_CLOEXEC))?;
+            let new = previous | libc::FD_CLOEXEC;
+            if new != previous {
+                cvt(libc::fcntl(self.fd, libc::F_SETFD, new))?;
+            }
+            Ok(())
+        }
+    }
+
+    #[cfg(target_os = "linux")]
+    pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
+        unsafe {
+            let v = nonblocking as c_int;
+            cvt(libc::ioctl(self.fd, libc::FIONBIO, &v))?;
             Ok(())
         }
     }
 
+    #[cfg(not(target_os = "linux"))]
     pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> {
         unsafe {
             let previous = cvt(libc::fcntl(self.fd, libc::F_GETFL))?;
@@ -157,7 +170,9 @@ impl FileDesc {
             } else {
                 previous & !libc::O_NONBLOCK
             };
-            cvt(libc::fcntl(self.fd, libc::F_SETFL, new))?;
+            if new != previous {
+                cvt(libc::fcntl(self.fd, libc::F_SETFL, new))?;
+            }
             Ok(())
         }
     }
diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp
index 34ee7d552f346..c7bcd2558186e 100644
--- a/src/rustllvm/RustWrapper.cpp
+++ b/src/rustllvm/RustWrapper.cpp
@@ -588,7 +588,11 @@ extern "C" LLVMRustMetadataRef LLVMRustDIBuilderCreateStaticVariable(
   }
 #endif
 
+#if LLVM_VERSION_GE(4, 0)
+  return wrap(Builder->createGlobalVariableExpression(
+#else
   return wrap(Builder->createGlobalVariable(
+#endif
       unwrapDI<DIDescriptor>(Context), Name, LinkageName,
       unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), IsLocalToUnit,
 #if LLVM_VERSION_GE(4, 0)
diff --git a/src/test/compile-fail/issue-32829.rs b/src/test/compile-fail/issue-32829.rs
index 9ac70882ca28c..e889c34700cf8 100644
--- a/src/test/compile-fail/issue-32829.rs
+++ b/src/test/compile-fail/issue-32829.rs
@@ -8,9 +8,85 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// error-pattern: calls in statics are limited
+#![feature(const_fn)]
 
-static S : u64 = { { panic!("foo"); 0 } };
+const bad: u32 = {
+    {
+        5; //~ ERROR: blocks in constants are limited to items and tail expressions
+        0
+    }
+};
+
+const bad_two: u32 = {
+    {
+        invalid();
+        //~^ ERROR: blocks in constants are limited to items and tail expressions
+        //~^^ ERROR: calls in constants are limited to constant functions, struct and enum
+        0
+    }
+};
+
+const bad_three: u32 = {
+    {
+        valid();
+        //~^ ERROR: blocks in constants are limited to items and tail expressions
+        0
+    }
+};
+
+static bad_four: u32 = {
+    {
+        5; //~ ERROR: blocks in statics are limited to items and tail expressions
+        0
+    }
+};
+
+static bad_five: u32 = {
+    {
+        invalid();
+        //~^ ERROR: blocks in statics are limited to items and tail expressions
+        //~^^ ERROR: calls in statics are limited to constant functions, struct and enum
+        0
+    }
+};
+
+static bad_six: u32 = {
+    {
+        valid();
+        //~^ ERROR: blocks in statics are limited to items and tail expressions
+        0
+    }
+};
+
+static mut bad_seven: u32 = {
+    {
+        5; //~ ERROR: blocks in statics are limited to items and tail expressions
+        0
+    }
+};
+
+static mut bad_eight: u32 = {
+    {
+        invalid();
+        //~^ ERROR: blocks in statics are limited to items and tail expressions
+        //~^^ ERROR: calls in statics are limited to constant functions, struct and enum
+        0
+    }
+};
+
+static mut bad_nine: u32 = {
+    {
+        valid();
+        //~^ ERROR: blocks in statics are limited to items and tail expressions
+        0
+    }
+};
+
+fn invalid() {}
+const fn valid() {}
+
+static S: u64 = { { panic!("foo"); 0 } };
+//~^ ERROR: calls in statics are limited
 
 fn main() {
     println!("{:?}", S);
diff --git a/src/test/compile-fail/issue32829.rs b/src/test/compile-fail/issue32829.rs
deleted file mode 100644
index e0b847fc99470..0000000000000
--- a/src/test/compile-fail/issue32829.rs
+++ /dev/null
@@ -1,88 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-#![feature(const_fn)]
-
-const bad : u32 = {
-    {
-        5; //~ ERROR: blocks in constants are limited to items and tail expressions
-        0
-    }
-};
-
-const bad_two : u32 = {
-    {
-        invalid();
-        //~^ ERROR: blocks in constants are limited to items and tail expressions
-        //~^^ ERROR: calls in constants are limited to constant functions, struct and enum
-        0
-    }
-};
-
-const bad_three : u32 = {
-    {
-        valid();
-        //~^ ERROR: blocks in constants are limited to items and tail expressions
-        0
-    }
-};
-
-static bad_four : u32 = {
-    {
-        5; //~ ERROR: blocks in statics are limited to items and tail expressions
-        0
-    }
-};
-
-static bad_five : u32 = {
-    {
-        invalid();
-        //~^ ERROR: blocks in statics are limited to items and tail expressions
-        //~^^ ERROR: calls in statics are limited to constant functions, struct and enum
-        0
-    }
-};
-
-static bad_six : u32 = {
-    {
-        valid();
-        //~^ ERROR: blocks in statics are limited to items and tail expressions
-        0
-    }
-};
-
-static mut bad_seven : u32 = {
-    {
-        5; //~ ERROR: blocks in statics are limited to items and tail expressions
-        0
-    }
-};
-
-static mut bad_eight : u32 = {
-    {
-        invalid();
-        //~^ ERROR: blocks in statics are limited to items and tail expressions
-        //~^^ ERROR: calls in statics are limited to constant functions, struct and enum
-        0
-    }
-};
-
-static mut bad_nine : u32 = {
-    {
-        valid();
-        //~^ ERROR: blocks in statics are limited to items and tail expressions
-        0
-    }
-};
-
-
-fn invalid() {}
-const fn valid() {}
-
-fn main() {}
diff --git a/src/test/debuginfo/borrowed-enum.rs b/src/test/debuginfo/borrowed-enum.rs
index c457fed7ecd52..9e63beff3cb2e 100644
--- a/src/test/debuginfo/borrowed-enum.rs
+++ b/src/test/debuginfo/borrowed-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/generic-struct-style-enum.rs b/src/test/debuginfo/generic-struct-style-enum.rs
index df56ccccca3f5..4a1d14ccf6118 100644
--- a/src/test/debuginfo/generic-struct-style-enum.rs
+++ b/src/test/debuginfo/generic-struct-style-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/generic-tuple-style-enum.rs b/src/test/debuginfo/generic-tuple-style-enum.rs
index e538700f0f84c..012bd6140cdbe 100644
--- a/src/test/debuginfo/generic-tuple-style-enum.rs
+++ b/src/test/debuginfo/generic-tuple-style-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/packed-struct.rs b/src/test/debuginfo/packed-struct.rs
index c476e9fe0796f..16e6371a9c0a9 100644
--- a/src/test/debuginfo/packed-struct.rs
+++ b/src/test/debuginfo/packed-struct.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/recursive-struct.rs b/src/test/debuginfo/recursive-struct.rs
index f33dfac07d203..75c2feb480ede 100644
--- a/src/test/debuginfo/recursive-struct.rs
+++ b/src/test/debuginfo/recursive-struct.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // ignore-lldb
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/struct-in-enum.rs b/src/test/debuginfo/struct-in-enum.rs
index d9763aedd7c15..bd044188dbcbc 100644
--- a/src/test/debuginfo/struct-in-enum.rs
+++ b/src/test/debuginfo/struct-in-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/struct-style-enum.rs b/src/test/debuginfo/struct-style-enum.rs
index 6212caa69538d..b156a3be699e3 100644
--- a/src/test/debuginfo/struct-style-enum.rs
+++ b/src/test/debuginfo/struct-style-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/tuple-style-enum.rs b/src/test/debuginfo/tuple-style-enum.rs
index f85cd6a50f519..f36153d1f5c5a 100644
--- a/src/test/debuginfo/tuple-style-enum.rs
+++ b/src/test/debuginfo/tuple-style-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/union-smoke.rs b/src/test/debuginfo/union-smoke.rs
index 844e9405ba55c..0b2544151fd32 100644
--- a/src/test/debuginfo/union-smoke.rs
+++ b/src/test/debuginfo/union-smoke.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/debuginfo/unique-enum.rs b/src/test/debuginfo/unique-enum.rs
index e8eb4315007af..5a99de7779cff 100644
--- a/src/test/debuginfo/unique-enum.rs
+++ b/src/test/debuginfo/unique-enum.rs
@@ -10,7 +10,7 @@
 
 // ignore-tidy-linelength
 // min-lldb-version: 310
-// ignore-gdb-version: 7.11.90 - 7.12
+// ignore-gdb-version: 7.11.90 - 7.12.9
 
 // compile-flags:-g
 
diff --git a/src/test/run-fail/bug-2470-bounds-check-overflow.rs b/src/test/run-fail/issue-2470-bounds-check-overflow.rs
similarity index 100%
rename from src/test/run-fail/bug-2470-bounds-check-overflow.rs
rename to src/test/run-fail/issue-2470-bounds-check-overflow.rs
diff --git a/src/test/run-fail/bug-811.rs b/src/test/run-fail/issue-811.rs
similarity index 100%
rename from src/test/run-fail/bug-811.rs
rename to src/test/run-fail/issue-811.rs
diff --git a/src/test/run-pass/i128-ffi.rs b/src/test/run-pass/i128-ffi.rs
index 222f32754fb6b..473f1cc2301dc 100644
--- a/src/test/run-pass/i128-ffi.rs
+++ b/src/test/run-pass/i128-ffi.rs
@@ -8,9 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// ignore-stage0
-// ignore-stage1
-
 // MSVC doesn't support 128 bit integers, and other Windows
 // C compilers have very inconsistent views on how the ABI
 // should look like.
diff --git a/src/test/run-pass/i128.rs b/src/test/run-pass/i128.rs
index 3eb1c95050267..dc4f0774b9771 100644
--- a/src/test/run-pass/i128.rs
+++ b/src/test/run-pass/i128.rs
@@ -8,9 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// ignore-stage0
-// ignore-stage1
-
 // ignore-emscripten
 
 #![feature(i128_type, test)]
diff --git a/src/test/run-pass/issue28498-must-work-ex1.rs b/src/test/run-pass/issue-28498-must-work-ex1.rs
similarity index 100%
rename from src/test/run-pass/issue28498-must-work-ex1.rs
rename to src/test/run-pass/issue-28498-must-work-ex1.rs
diff --git a/src/test/run-pass/issue28498-must-work-ex2.rs b/src/test/run-pass/issue-28498-must-work-ex2.rs
similarity index 100%
rename from src/test/run-pass/issue28498-must-work-ex2.rs
rename to src/test/run-pass/issue-28498-must-work-ex2.rs
diff --git a/src/test/run-pass/issue28498-ugeh-ex1.rs b/src/test/run-pass/issue-28498-ugeh-ex1.rs
similarity index 100%
rename from src/test/run-pass/issue28498-ugeh-ex1.rs
rename to src/test/run-pass/issue-28498-ugeh-ex1.rs
diff --git a/src/test/run-pass/issue28498-ugeh-with-lifetime-param.rs b/src/test/run-pass/issue-28498-ugeh-with-lifetime-param.rs
similarity index 100%
rename from src/test/run-pass/issue28498-ugeh-with-lifetime-param.rs
rename to src/test/run-pass/issue-28498-ugeh-with-lifetime-param.rs
diff --git a/src/test/run-pass/issue28498-ugeh-with-passed-to-fn.rs b/src/test/run-pass/issue-28498-ugeh-with-passed-to-fn.rs
similarity index 100%
rename from src/test/run-pass/issue28498-ugeh-with-passed-to-fn.rs
rename to src/test/run-pass/issue-28498-ugeh-with-passed-to-fn.rs
diff --git a/src/test/run-pass/issue28498-ugeh-with-trait-bound.rs b/src/test/run-pass/issue-28498-ugeh-with-trait-bound.rs
similarity index 100%
rename from src/test/run-pass/issue28498-ugeh-with-trait-bound.rs
rename to src/test/run-pass/issue-28498-ugeh-with-trait-bound.rs
diff --git a/src/test/run-pass/issue-38987.rs b/src/test/run-pass/issue-38987.rs
index 29e96c162b8de..a513476d4a33a 100644
--- a/src/test/run-pass/issue-38987.rs
+++ b/src/test/run-pass/issue-38987.rs
@@ -9,10 +9,6 @@
 // except according to those terms.
 #![feature(i128_type)]
 
-// SNAP: run on all stages after snapshot, i128 currently doesn't work on stages 0 and 1
-// ignore-stage1
-// ignore-stage0
-
 fn main() {
     let _ = -0x8000_0000_0000_0000_0000_0000_0000_0000i128;
 }
diff --git a/src/test/run-pass/bug-7183-generics.rs b/src/test/run-pass/issue-7183-generics.rs
similarity index 100%
rename from src/test/run-pass/bug-7183-generics.rs
rename to src/test/run-pass/issue-7183-generics.rs
diff --git a/src/test/run-pass/bug-7295.rs b/src/test/run-pass/issue-7295.rs
similarity index 100%
rename from src/test/run-pass/bug-7295.rs
rename to src/test/run-pass/issue-7295.rs
diff --git a/src/test/run-pass/issue29927-1.rs b/src/test/run-pass/issue29927.rs
similarity index 100%
rename from src/test/run-pass/issue29927-1.rs
rename to src/test/run-pass/issue29927.rs
diff --git a/src/test/ui/span/issue28498-reject-ex1.rs b/src/test/ui/span/issue-28498-reject-ex1.rs
similarity index 100%
rename from src/test/ui/span/issue28498-reject-ex1.rs
rename to src/test/ui/span/issue-28498-reject-ex1.rs
diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.rs b/src/test/ui/span/issue-28498-reject-lifetime-param.rs
similarity index 100%
rename from src/test/ui/span/issue28498-reject-lifetime-param.rs
rename to src/test/ui/span/issue-28498-reject-lifetime-param.rs
diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.rs b/src/test/ui/span/issue-28498-reject-passed-to-fn.rs
similarity index 100%
rename from src/test/ui/span/issue28498-reject-passed-to-fn.rs
rename to src/test/ui/span/issue-28498-reject-passed-to-fn.rs
diff --git a/src/test/ui/span/issue28498-reject-trait-bound.rs b/src/test/ui/span/issue-28498-reject-trait-bound.rs
similarity index 100%
rename from src/test/ui/span/issue28498-reject-trait-bound.rs
rename to src/test/ui/span/issue-28498-reject-trait-bound.rs