about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-11-24 15:11:11 +0000
committerbors <bors@rust-lang.org>2017-11-24 15:11:11 +0000
commit5f44c653cff61d0f55f53e07a188f755c7acddd1 (patch)
tree5fa1e64973c8f8316b714ceb40ffd31fe5e9539c /src/test
parent71da1c21ebc79f19e749344c8b4e2c13f533872e (diff)
parent42208c122757fca706bc5224f3a0c7200fae32e9 (diff)
Auto merge of #46093 - scottmcm:lower-128-mir, r=nagisa
Add a MIR pass to lower 128-bit operators to lang item calls

Runs only with `-Z lower_128bit_ops` since it's not hooked into targets yet.

This isn't really useful on its own, but the declarations for the lang items need to be in the compiler before compiler-builtins can be updated to define them, so this is part 1 of at least 3.

cc https://github.com/rust-lang/rust/issues/45676 @est31 @nagisa
Diffstat (limited to 'src/test')
-rw-r--r--src/test/mir-opt/lower_128bit_debug_test.rs145
-rw-r--r--src/test/mir-opt/lower_128bit_test.rs108
2 files changed, 253 insertions, 0 deletions
diff --git a/src/test/mir-opt/lower_128bit_debug_test.rs b/src/test/mir-opt/lower_128bit_debug_test.rs
new file mode 100644
index 00000000000..4626dc17e1f
--- /dev/null
+++ b/src/test/mir-opt/lower_128bit_debug_test.rs
@@ -0,0 +1,145 @@
+// 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.
+
+// compile-flags: -Z lower_128bit_ops -C debug_assertions=yes
+
+#![feature(i128_type)]
+#![feature(lang_items)]
+
+#[lang="i128_div"]
+fn i128_div(_x: i128, _y: i128) -> i128 { 3 }
+#[lang="u128_div"]
+fn u128_div(_x: u128, _y: u128) -> u128 { 4 }
+#[lang="i128_rem"]
+fn i128_rem(_x: i128, _y: i128) -> i128 { 5 }
+#[lang="u128_rem"]
+fn u128_rem(_x: u128, _y: u128) -> u128 { 6 }
+
+#[lang="i128_addo"]
+fn i128_addo(_x: i128, _y: i128) -> (i128, bool) { (0, false) }
+#[lang="u128_addo"]
+fn u128_addo(_x: u128, _y: u128) -> (u128, bool) { (1, false) }
+#[lang="i128_subo"]
+fn i128_subo(_x: i128, _y: i128) -> (i128, bool) { (2, false) }
+#[lang="u128_subo"]
+fn u128_subo(_x: u128, _y: u128) -> (u128, bool) { (3, false) }
+#[lang="i128_mulo"]
+fn i128_mulo(_x: i128, _y: i128) -> (i128, bool) { (4, false) }
+#[lang="u128_mulo"]
+fn u128_mulo(_x: u128, _y: u128) -> (u128, bool) { (5, false) }
+#[lang="i128_shlo"]
+fn i128_shlo(_x: i128, _y: u128) -> (i128, bool) { (6, false) }
+#[lang="u128_shlo"]
+fn u128_shlo(_x: u128, _y: u128) -> (u128, bool) { (6, false) }
+#[lang="i128_shro"]
+fn i128_shro(_x: i128, _y: u128) -> (i128, bool) { (7, false) }
+#[lang="u128_shro"]
+fn u128_shro(_x: u128, _y: u128) -> (u128, bool) { (8, false) }
+
+fn test_signed(mut x: i128) -> i128 {
+    x += 1;
+    x -= 2;
+    x *= 3;
+    x /= 4;
+    x %= 5;
+    x <<= 6;
+    x >>= 7;
+    x
+}
+
+fn test_unsigned(mut x: u128) -> u128 {
+    x += 1;
+    x -= 2;
+    x *= 3;
+    x /= 4;
+    x %= 5;
+    x <<= 6;
+    x >>= 7;
+    x
+}
+
+fn main() {
+    test_signed(-200);
+    test_unsigned(200);
+}
+
+// END RUST SOURCE
+
+// START rustc.test_signed.Lower128Bit.after.mir
+//     _2 = const i128_addo(_1, const 1i128) -> bb10;
+//     ...
+//     _1 = (_2.0: i128);
+//     _3 = const i128_subo(_1, const 2i128) -> bb11;
+//     ...
+//     _1 = (_3.0: i128);
+//     _4 = const i128_mulo(_1, const 3i128) -> bb12;
+//     ...
+//     _1 = (_4.0: i128);
+//     ...
+//     _1 = const i128_div(_1, const 4i128) -> bb13;
+//     ...
+//     _1 = const i128_rem(_1, const 5i128) -> bb15;
+//     ...
+//     _1 = (_13.0: i128);
+//     ...
+//     _17 = const 7i32 as u128 (Misc);
+//     _14 = const i128_shro(_1, _17) -> bb16;
+//     ...
+//     _1 = (_14.0: i128);
+//     ...
+//     assert(!(_2.1: bool), "attempt to add with overflow") -> bb1;
+//     ...
+//     assert(!(_3.1: bool), "attempt to subtract with overflow") -> bb2;
+//     ...
+//     assert(!(_4.1: bool), "attempt to multiply with overflow") -> bb3;
+//     ...
+//     assert(!(_13.1: bool), "attempt to shift left with overflow") -> bb8;
+//     ...
+//     _16 = const 6i32 as u128 (Misc);
+//     _13 = const i128_shlo(_1, _16) -> bb14;
+//     ...
+//     assert(!(_14.1: bool), "attempt to shift right with overflow") -> bb9;
+// END rustc.test_signed.Lower128Bit.after.mir
+
+// START rustc.test_unsigned.Lower128Bit.after.mir
+//     _2 = const u128_addo(_1, const 1u128) -> bb8;
+//     ...
+//     _1 = (_2.0: u128);
+//     _3 = const u128_subo(_1, const 2u128) -> bb9;
+//     ...
+//     _1 = (_3.0: u128);
+//     _4 = const u128_mulo(_1, const 3u128) -> bb10;
+//     ...
+//     _1 = (_4.0: u128);
+//     ...
+//     _1 = const u128_div(_1, const 4u128) -> bb11;
+//     ...
+//     _1 = const u128_rem(_1, const 5u128) -> bb13;
+//     ...
+//     _1 = (_7.0: u128);
+//     ...
+//     _11 = const 7i32 as u128 (Misc);
+//     _8 = const u128_shro(_1, _11) -> bb14;
+//     ...
+//     _1 = (_8.0: u128);
+//     ...
+//     assert(!(_2.1: bool), "attempt to add with overflow") -> bb1;
+//     ...
+//     assert(!(_3.1: bool), "attempt to subtract with overflow") -> bb2;
+//     ...
+//     assert(!(_4.1: bool), "attempt to multiply with overflow") -> bb3;
+//     ...
+//     assert(!(_7.1: bool), "attempt to shift left with overflow") -> bb6;
+//     ...
+//     _10 = const 6i32 as u128 (Misc);
+//     _7 = const u128_shlo(_1, _10) -> bb12;
+//     ...
+//     assert(!(_8.1: bool), "attempt to shift right with overflow") -> bb7;
+// END rustc.test_unsigned.Lower128Bit.after.mir
diff --git a/src/test/mir-opt/lower_128bit_test.rs b/src/test/mir-opt/lower_128bit_test.rs
new file mode 100644
index 00000000000..207cd0ac57e
--- /dev/null
+++ b/src/test/mir-opt/lower_128bit_test.rs
@@ -0,0 +1,108 @@
+// 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.
+
+// compile-flags: -Z lower_128bit_ops -C debug_assertions=no
+
+#![feature(i128_type)]
+#![feature(lang_items)]
+
+#[lang="i128_add"]
+fn i128_add(_x: i128, _y: i128) -> i128 { 0 }
+#[lang="u128_add"]
+fn u128_add(_x: u128, _y: u128) -> u128 { 0 }
+#[lang="i128_sub"]
+fn i128_sub(_x: i128, _y: i128) -> i128 { 1 }
+#[lang="u128_sub"]
+fn u128_sub(_x: u128, _y: u128) -> u128 { 1 }
+#[lang="i128_mul"]
+fn i128_mul(_x: i128, _y: i128) -> i128 { 2 }
+#[lang="u128_mul"]
+fn u128_mul(_x: u128, _y: u128) -> u128 { 2 }
+#[lang="i128_div"]
+fn i128_div(_x: i128, _y: i128) -> i128 { 3 }
+#[lang="u128_div"]
+fn u128_div(_x: u128, _y: u128) -> u128 { 4 }
+#[lang="i128_rem"]
+fn i128_rem(_x: i128, _y: i128) -> i128 { 5 }
+#[lang="u128_rem"]
+fn u128_rem(_x: u128, _y: u128) -> u128 { 6 }
+#[lang="i128_shl"]
+fn i128_shl(_x: i128, _y: u32) -> i128 { 7 }
+#[lang="u128_shl"]
+fn u128_shl(_x: u128, _y: u32) -> u128 { 7 }
+#[lang="i128_shr"]
+fn i128_shr(_x: i128, _y: u32) -> i128 { 8 }
+#[lang="u128_shr"]
+fn u128_shr(_x: u128, _y: u32) -> u128 { 9 }
+
+fn test_signed(mut x: i128) -> i128 {
+    x += 1;
+    x -= 2;
+    x *= 3;
+    x /= 4;
+    x %= 5;
+    x <<= 6;
+    x >>= 7;
+    x
+}
+
+fn test_unsigned(mut x: u128) -> u128 {
+    x += 1;
+    x -= 2;
+    x *= 3;
+    x /= 4;
+    x %= 5;
+    x <<= 6;
+    x >>= 7;
+    x
+}
+
+fn main() {
+    test_signed(-200);
+    test_unsigned(200);
+}
+
+// END RUST SOURCE
+
+// START rustc.test_signed.Lower128Bit.after.mir
+//     _1 = const i128_add(_1, const 1i128) -> bb7;
+//     ...
+//     _1 = const i128_div(_1, const 4i128) -> bb8;
+//     ...
+//     _1 = const i128_rem(_1, const 5i128) -> bb11;
+//     ...
+//     _1 = const i128_mul(_1, const 3i128) -> bb5;
+//     ...
+//     _1 = const i128_sub(_1, const 2i128) -> bb6;
+//     ...
+//     _11 = const 7i32 as u32 (Misc);
+//     _1 = const i128_shr(_1, _11) -> bb9;
+//     ...
+//     _12 = const 6i32 as u32 (Misc);
+//     _1 = const i128_shl(_1, _12) -> bb10;
+// END rustc.test_signed.Lower128Bit.after.mir
+
+// START rustc.test_unsigned.Lower128Bit.after.mir
+//     _1 = const u128_add(_1, const 1u128) -> bb5;
+//     ...
+//     _1 = const u128_div(_1, const 4u128) -> bb6;
+//     ...
+//     _1 = const u128_rem(_1, const 5u128) -> bb9;
+//     ...
+//     _1 = const u128_mul(_1, const 3u128) -> bb3;
+//     ...
+//     _1 = const u128_sub(_1, const 2u128) -> bb4;
+//     ...
+//     _5 = const 7i32 as u32 (Misc);
+//     _1 = const u128_shr(_1, _5) -> bb7;
+//     ...
+//     _6 = const 6i32 as u32 (Misc);
+//     _1 = const u128_shl(_1, _6) -> bb8;
+// END rustc.test_unsigned.Lower128Bit.after.mir