Skip to content

Commit 7600c02

Browse files
committed
Cleanup of raw_eq in codegen cranelift, gcc and tests
1 parent 780d37c commit 7600c02

File tree

5 files changed

+1
-104
lines changed

5 files changed

+1
-104
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

-34
Original file line numberDiff line numberDiff line change
@@ -1101,40 +1101,6 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
11011101
ret.write_cvalue(fx, CValue::by_val(res, ret.layout()));
11021102
};
11031103

1104-
raw_eq, <T>(v lhs_ref, v rhs_ref) {
1105-
fn type_by_size(size: Size) -> Option<Type> {
1106-
Type::int(size.bits().try_into().ok()?)
1107-
}
1108-
1109-
let size = fx.layout_of(T).layout.size;
1110-
// FIXME add and use emit_small_memcmp
1111-
let is_eq_value =
1112-
if size == Size::ZERO {
1113-
// No bytes means they're trivially equal
1114-
fx.bcx.ins().iconst(types::I8, 1)
1115-
} else if let Some(clty) = type_by_size(size) {
1116-
// Can't use `trusted` for these loads; they could be unaligned.
1117-
let mut flags = MemFlags::new();
1118-
flags.set_notrap();
1119-
let lhs_val = fx.bcx.ins().load(clty, flags, lhs_ref, 0);
1120-
let rhs_val = fx.bcx.ins().load(clty, flags, rhs_ref, 0);
1121-
let eq = fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val);
1122-
fx.bcx.ins().bint(types::I8, eq)
1123-
} else {
1124-
// Just call `memcmp` (like slices do in core) when the
1125-
// size is too large or it's not a power-of-two.
1126-
let signed_bytes = i64::try_from(size.bytes()).unwrap();
1127-
let bytes_val = fx.bcx.ins().iconst(fx.pointer_type, signed_bytes);
1128-
let params = vec![AbiParam::new(fx.pointer_type); 3];
1129-
let returns = vec![AbiParam::new(types::I32)];
1130-
let args = &[lhs_ref, rhs_ref, bytes_val];
1131-
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
1132-
let eq = fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0);
1133-
fx.bcx.ins().bint(types::I8, eq)
1134-
};
1135-
ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
1136-
};
1137-
11381104
black_box, (c a) {
11391105
// FIXME implement black_box semantics
11401106
ret.write_cvalue(fx, a);

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+1-42
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ mod simd;
44
use gccjit::{ComparisonOp, Function, RValue, ToRValue, Type, UnaryOp};
55
use rustc_codegen_ssa::MemFlags;
66
use rustc_codegen_ssa::base::wants_msvc_seh;
7-
use rustc_codegen_ssa::common::{IntPredicate, span_invalid_monomorphization_error};
7+
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
88
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
99
use rustc_codegen_ssa::mir::place::PlaceRef;
1010
use rustc_codegen_ssa::traits::{ArgAbiMethods, BaseTypeMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
1111
use rustc_middle::bug;
1212
use rustc_middle::ty::{self, Instance, Ty};
1313
use rustc_middle::ty::layout::LayoutOf;
1414
use rustc_span::{Span, Symbol, symbol::kw, sym};
15-
use rustc_target::abi::HasDataLayout;
1615
use rustc_target::abi::call::{ArgAbi, FnAbi, PassMode};
1716
use rustc_target::spec::PanicStrategy;
1817

@@ -268,46 +267,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
268267
}
269268
}
270269

271-
sym::raw_eq => {
272-
use rustc_target::abi::Abi::*;
273-
let tp_ty = substs.type_at(0);
274-
let layout = self.layout_of(tp_ty).layout;
275-
let _use_integer_compare = match layout.abi {
276-
Scalar(_) | ScalarPair(_, _) => true,
277-
Uninhabited | Vector { .. } => false,
278-
Aggregate { .. } => {
279-
// For rusty ABIs, small aggregates are actually passed
280-
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
281-
// so we re-use that same threshold here.
282-
layout.size <= self.data_layout().pointer_size * 2
283-
}
284-
};
285-
286-
let a = args[0].immediate();
287-
let b = args[1].immediate();
288-
if layout.size.bytes() == 0 {
289-
self.const_bool(true)
290-
}
291-
/*else if use_integer_compare {
292-
let integer_ty = self.type_ix(layout.size.bits()); // FIXME(antoyo): LLVM creates an integer of 96 bits for [i32; 3], but gcc doesn't support this, so it creates an integer of 128 bits.
293-
let ptr_ty = self.type_ptr_to(integer_ty);
294-
let a_ptr = self.bitcast(a, ptr_ty);
295-
let a_val = self.load(integer_ty, a_ptr, layout.align.abi);
296-
let b_ptr = self.bitcast(b, ptr_ty);
297-
let b_val = self.load(integer_ty, b_ptr, layout.align.abi);
298-
self.icmp(IntPredicate::IntEQ, a_val, b_val)
299-
}*/
300-
else {
301-
let void_ptr_type = self.context.new_type::<*const ()>();
302-
let a_ptr = self.bitcast(a, void_ptr_type);
303-
let b_ptr = self.bitcast(b, void_ptr_type);
304-
let n = self.context.new_cast(None, self.const_usize(layout.size.bytes()), self.sizet_type);
305-
let builtin = self.context.get_builtin_function("memcmp");
306-
let cmp = self.context.new_call(None, builtin, &[a_ptr, b_ptr, n]);
307-
self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0))
308-
}
309-
}
310-
311270
sym::black_box => {
312271
args[0].val.store(self, result);
313272

src/test/codegen/loads.rs

-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,3 @@ pub fn small_array_alignment(x: [i8; 4]) -> [i8; 4] {
3131
// CHECK: ret [4 x i8] [[VAR]]
3232
x
3333
}
34-
35-
// CHECK-LABEL: @small_struct_alignment
36-
#[no_mangle]
37-
pub fn small_struct_alignment(x: Bytes) -> Bytes {
38-
// TODO-CHECK: [[VAR:%[0-9]+]] = load {{(i32, )?}}i32* %{{.*}}, align 1
39-
// TODO-CHECK: ret i32 [[VAR]]
40-
x
41-
}

src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.rs

-11
This file was deleted.

src/test/ui/intrinsics/intrinsic-raw_eq-const-padding.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)