]> git.lizzy.rs Git - rust.git/blob - src/test/mir-opt/lower_128bit_test.rs
Rollup merge of #52656 - jD91mZM2:stablize-uds, r=alexcrichton
[rust.git] / src / test / mir-opt / lower_128bit_test.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // ignore-emscripten
12
13 // compile-flags: -Z lower_128bit_ops=yes -C debug_assertions=no
14
15 #![feature(const_fn)]
16
17 static TEST_SIGNED: i128 = const_signed(-222);
18 static TEST_UNSIGNED: u128 = const_unsigned(200);
19
20 const fn const_signed(mut x: i128) -> i128 {
21     ((((((x + 1) - 2) * 3) / 4) % 5) << 6) >> 7
22 }
23
24 const fn const_unsigned(mut x: u128) -> u128 {
25     ((((((x + 1) - 2) * 3) / 4) % 5) << 6) >> 7
26 }
27
28 fn test_signed(mut x: i128) -> i128 {
29     x += 1;
30     x -= 2;
31     x *= 3;
32     x /= 4;
33     x %= 5;
34     x <<= 6;
35     x >>= 7;
36     x
37 }
38
39 fn test_unsigned(mut x: u128) -> u128 {
40     x += 1;
41     x -= 2;
42     x *= 3;
43     x /= 4;
44     x %= 5;
45     x <<= 6;
46     x >>= 7;
47     x
48 }
49
50 fn check(x: i128, y: u128) {
51     assert_eq!(test_signed(x), -1);
52     assert_eq!(const_signed(x), -1);
53     assert_eq!(TEST_SIGNED, -1);
54     assert_eq!(test_unsigned(y), 2);
55     assert_eq!(const_unsigned(y), 2);
56     assert_eq!(TEST_UNSIGNED, 2);
57 }
58
59 fn main() {
60     check(-222, 200);
61 }
62
63 // END RUST SOURCE
64
65 // START rustc.const_signed.Lower128Bit.after.mir
66 //     _8 = _1;
67 //     _9 = const compiler_builtins::int::addsub::rust_i128_addo(move _8, const 1i128) -> bb10;
68 //     ...
69 //     _7 = move (_9.0: i128);
70 //     ...
71 //     _10 = const compiler_builtins::int::addsub::rust_i128_subo(move _7, const 2i128) -> bb11;
72 //     ...
73 //     _6 = move (_10.0: i128);
74 //     ...
75 //     _11 = const compiler_builtins::int::mul::rust_i128_mulo(move _6, const 3i128) -> bb12;
76 //     ...
77 //     _5 = move (_11.0: i128);
78 //     ...
79 //     _12 = Eq(const 4i128, const 0i128);
80 //     assert(!move _12, "attempt to divide by zero") -> bb4;
81 //     ...
82 //     _13 = Eq(const 4i128, const -1i128);
83 //     _14 = Eq(_5, const -170141183460469231731687303715884105728i128);
84 //     _15 = BitAnd(move _13, move _14);
85 //     assert(!move _15, "attempt to divide with overflow") -> bb5;
86 //     ...
87 //     _4 = const compiler_builtins::int::sdiv::rust_i128_div(move _5, const 4i128) -> bb13;
88 //     ...
89 //     _17 = Eq(const 5i128, const -1i128);
90 //     _18 = Eq(_4, const -170141183460469231731687303715884105728i128);
91 //     _19 = BitAnd(move _17, move _18);
92 //     assert(!move _19, "attempt to calculate the remainder with overflow") -> bb7;
93 //     ...
94 //     _3 = const compiler_builtins::int::sdiv::rust_i128_rem(move _4, const 5i128) -> bb15;
95 //     ...
96 //     _2 = move (_20.0: i128);
97 //     ...
98 //     _23 = const 7i32 as u128 (Misc);
99 //     _21 = const compiler_builtins::int::shift::rust_i128_shro(move _2, move _23) -> bb16;
100 //     ...
101 //     _0 = move (_21.0: i128);
102 //     ...
103 //     assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
104 //     ...
105 //     assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
106 //     ...
107 //     assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
108 //     ...
109 //     _16 = Eq(const 5i128, const 0i128);
110 //     assert(!move _16, "attempt to calculate the remainder with a divisor of zero") -> bb6;
111 //     ...
112 //     assert(!move (_20.1: bool), "attempt to shift left with overflow") -> bb8;
113 //     ...
114 //     _22 = const 6i32 as u128 (Misc);
115 //     _20 = const compiler_builtins::int::shift::rust_i128_shlo(move _3, move _22) -> bb14;
116 //     ...
117 //     assert(!move (_21.1: bool), "attempt to shift right with overflow") -> bb9;
118 // END rustc.const_signed.Lower128Bit.after.mir
119
120 // START rustc.const_unsigned.Lower128Bit.after.mir
121 //     _8 = _1;
122 //     _9 = const compiler_builtins::int::addsub::rust_u128_addo(move _8, const 1u128) -> bb8;
123 //     ...
124 //     _7 = move (_9.0: u128);
125 //     ...
126 //     _10 = const compiler_builtins::int::addsub::rust_u128_subo(move _7, const 2u128) -> bb9;
127 //     ...
128 //     _6 = move (_10.0: u128);
129 //     ...
130 //     _11 = const compiler_builtins::int::mul::rust_u128_mulo(move _6, const 3u128) -> bb10;
131 //     ...
132 //     _5 = move (_11.0: u128);
133 //     ...
134 //     _12 = Eq(const 4u128, const 0u128);
135 //     assert(!move _12, "attempt to divide by zero") -> bb4;
136 //     ...
137 //     _4 = const compiler_builtins::int::udiv::rust_u128_div(move _5, const 4u128) -> bb11;
138 //     ...
139 //     _3 = const compiler_builtins::int::udiv::rust_u128_rem(move _4, const 5u128) -> bb13;
140 //     ...
141 //     _2 = move (_14.0: u128);
142 //     ...
143 //     _17 = const 7i32 as u128 (Misc);
144 //     _15 = const compiler_builtins::int::shift::rust_u128_shro(move _2, move _17) -> bb14;
145 //     ...
146 //     _0 = move (_15.0: u128);
147 //     ...
148 //     assert(!move (_9.1: bool), "attempt to add with overflow") -> bb1;
149 //     ...
150 //     assert(!move (_10.1: bool), "attempt to subtract with overflow") -> bb2;
151 //     ...
152 //     assert(!move (_11.1: bool), "attempt to multiply with overflow") -> bb3;
153 //     ...
154 //     _13 = Eq(const 5u128, const 0u128);
155 //     assert(!move _13, "attempt to calculate the remainder with a divisor of zero") -> bb5;
156 //     ...
157 //     assert(!move (_14.1: bool), "attempt to shift left with overflow") -> bb6;
158 //     ...
159 //     _16 = const 6i32 as u128 (Misc);
160 //     _14 = const compiler_builtins::int::shift::rust_u128_shlo(move _3, move _16) -> bb12;
161 //     ...
162 //     assert(!move (_15.1: bool), "attempt to shift right with overflow") -> bb7;
163 // END rustc.const_unsigned.Lower128Bit.after.mir
164
165 // START rustc.test_signed.Lower128Bit.after.mir
166 //     _1 = const compiler_builtins::int::addsub::rust_i128_add(_1, const 1i128) -> bb7;
167 //     ...
168 //     _1 = const compiler_builtins::int::sdiv::rust_i128_div(_1, const 4i128) -> bb8;
169 //     ...
170 //     _1 = const compiler_builtins::int::sdiv::rust_i128_rem(_1, const 5i128) -> bb11;
171 //     ...
172 //     _1 = const compiler_builtins::int::mul::rust_i128_mul(_1, const 3i128) -> bb5;
173 //     ...
174 //     _1 = const compiler_builtins::int::addsub::rust_i128_sub(_1, const 2i128) -> bb6;
175 //     ...
176 //     _10 = const 7i32 as u32 (Misc);
177 //     _1 = const compiler_builtins::int::shift::rust_i128_shr(_1, move _10) -> bb9;
178 //     ...
179 //     _11 = const 6i32 as u32 (Misc);
180 //     _1 = const compiler_builtins::int::shift::rust_i128_shl(_1, move _11) -> bb10;
181 // END rustc.test_signed.Lower128Bit.after.mir
182
183 // START rustc.test_unsigned.Lower128Bit.after.mir
184 //     _1 = const compiler_builtins::int::addsub::rust_u128_add(_1, const 1u128) -> bb5;
185 //     ...
186 //     _1 = const compiler_builtins::int::udiv::rust_u128_div(_1, const 4u128) -> bb6;
187 //     ...
188 //     _1 = const compiler_builtins::int::udiv::rust_u128_rem(_1, const 5u128) -> bb9;
189 //     ...
190 //     _1 = const compiler_builtins::int::mul::rust_u128_mul(_1, const 3u128) -> bb3;
191 //     ...
192 //     _1 = const compiler_builtins::int::addsub::rust_u128_sub(_1, const 2u128) -> bb4;
193 //     ...
194 //     _4 = const 7i32 as u32 (Misc);
195 //     _1 = const compiler_builtins::int::shift::rust_u128_shr(_1, move _4) -> bb7;
196 //     ...
197 //     _5 = const 6i32 as u32 (Misc);
198 //     _1 = const compiler_builtins::int::shift::rust_u128_shl(_1, move _5) -> bb8;
199 // END rustc.test_unsigned.Lower128Bit.after.mir