@@ -97,70 +97,23 @@ pub(crate) fn maybe_codegen<'tcx>(
97
97
None
98
98
};
99
99
100
- // Optimize `val >> 64`, because compiler_builtins uses it to deconstruct an 128bit
101
- // integer into its lsb and msb.
102
- // https://github.com/rust-lang-nursery/compiler-builtins/blob/79a6a1603d5672cbb9187ff41ff4d9b5048ac1cb/src/int/mod.rs#L217
103
- if resolve_value_imm(fx.bcx.func, rhs_val) == Some(64) {
104
- let (lhs_lsb, lhs_msb) = fx.bcx.ins().isplit(lhs_val);
105
- let all_zeros = fx.bcx.ins().iconst(types::I64, 0);
106
- let val = match (bin_op, is_signed) {
107
- (BinOp::Shr, false) => {
108
- let val = fx.bcx.ins().iconcat(lhs_msb, all_zeros);
109
- Some(CValue::by_val(val, fx.layout_of(fx.tcx.types.u128)))
110
- }
111
- (BinOp::Shr, true) => {
112
- let sign = fx.bcx.ins().icmp_imm(IntCC::SignedLessThan, lhs_msb, 0);
113
- let all_ones = fx.bcx.ins().iconst(types::I64, u64::MAX as i64);
114
- let all_sign_bits = fx.bcx.ins().select(sign, all_zeros, all_ones);
115
-
116
- let val = fx.bcx.ins().iconcat(lhs_msb, all_sign_bits);
117
- Some(CValue::by_val(val, fx.layout_of(fx.tcx.types.i128)))
118
- }
119
- (BinOp::Shl, _) => {
120
- let val_ty = if is_signed {
121
- fx.tcx.types.i128
122
- } else {
123
- fx.tcx.types.u128
124
- };
125
- let val = fx.bcx.ins().iconcat(all_zeros, lhs_lsb);
126
- Some(CValue::by_val(val, fx.layout_of(val_ty)))
127
- }
128
- _ => None,
129
- };
130
- if let Some(val) = val {
131
- if let Some(is_overflow) = is_overflow {
132
- let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
133
- let val = val.load_scalar(fx);
134
- return Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)));
100
+ let truncated_rhs = clif_intcast(fx, rhs_val, types::I32, false);
101
+ let val = match bin_op {
102
+ BinOp::Shl => fx.bcx.ins().ishl(lhs_val, truncated_rhs),
103
+ BinOp::Shr => {
104
+ if is_signed {
105
+ fx.bcx.ins().sshr(lhs_val, truncated_rhs)
135
106
} else {
136
- return Some(val);
107
+ fx.bcx.ins().ushr(lhs_val, truncated_rhs)
137
108
}
138
109
}
139
- }
140
-
141
- let truncated_rhs = clif_intcast(fx, rhs_val, types::I32, false);
142
- let truncated_rhs = CValue::by_val(truncated_rhs, fx.layout_of(fx.tcx.types.u32));
143
- let val = match (bin_op, is_signed) {
144
- (BinOp::Shl, false) => {
145
- fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.tcx.types.u128)
146
- }
147
- (BinOp::Shl, true) => {
148
- fx.easy_call("__ashlti3", &[lhs, truncated_rhs], fx.tcx.types.i128)
149
- }
150
- (BinOp::Shr, false) => {
151
- fx.easy_call("__lshrti3", &[lhs, truncated_rhs], fx.tcx.types.u128)
152
- }
153
- (BinOp::Shr, true) => {
154
- fx.easy_call("__ashrti3", &[lhs, truncated_rhs], fx.tcx.types.i128)
155
- }
156
- (_, _) => unreachable!(),
110
+ _ => unreachable!(),
157
111
};
158
112
if let Some(is_overflow) = is_overflow {
159
113
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
160
- let val = val.load_scalar(fx);
161
114
Some(CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty)))
162
115
} else {
163
- Some(val)
116
+ Some(CValue::by_val( val, lhs.layout()) )
164
117
}
165
118
}
166
119
}
0 commit comments