Skip to content

Commit 78ee67c

Browse files
committed
Fix: fix raw_eq being missing
1 parent f00c29f commit 78ee67c

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

crates/rustc_codegen_nvvm/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Notable changes to this project will be documented in this file.
44

55
## Unreleased
66

7+
## 0.2.3 - 1/2/22
8+
9+
- Fixed the `raw_eq` intrinsic being undefined.
10+
711
## 0.2.2 - 12/5/21
812

913
- Pass all ADTs directly, fixing certain structs being passed indirectly because they are scalar pairs.

crates/rustc_codegen_nvvm/src/ctx_intrinsics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
3636
let t_i128 = self.type_vector(t_i64, 2);
3737
let t_f32 = self.type_f32();
3838
let t_f64 = self.type_f64();
39+
let t_isize = self.type_isize();
3940

4041
let t_i8_i1 = self.type_struct(&[t_i8, i1], false);
4142
let t_i16_i1 = self.type_struct(&[t_i16, i1], false);
@@ -176,6 +177,10 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
176177
ifn!(map, "llvm.expect.i1", fn(i1, i1) -> i1);
177178
ifn!(map, "llvm.prefetch", fn(i8p, t_i32, t_i32, t_i32) -> void);
178179

180+
// This isn't an "LLVM intrinsic", but LLVM's optimization passes
181+
// recognize it like one and we assume it exists in `core::slice::cmp`
182+
ifn!(map, "memcmp", fn(i8p, i8p, t_isize) -> t_i32);
183+
179184
ifn!(map, "llvm.va_start", fn(i8p) -> void);
180185
ifn!(map, "llvm.va_end", fn(i8p) -> void);
181186
ifn!(map, "llvm.va_copy", fn(i8p, i8p) -> void);

crates/rustc_codegen_nvvm/src/intrinsic.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::ty::LayoutLlvmExt;
55
use crate::{builder::Builder, context::CodegenCx};
66
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
77
use rustc_codegen_ssa::mir::place::PlaceRef;
8+
use rustc_codegen_ssa::traits::DerivedTypeMethods;
89
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods, ConstMethods, OverflowOp};
910
use rustc_codegen_ssa::{mir::operand::OperandRef, traits::IntrinsicCallMethods};
1011
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
@@ -425,6 +426,44 @@ impl<'a, 'll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
425426
}
426427
}
427428
}
429+
sym::raw_eq => {
430+
use abi::Abi::*;
431+
use rustc_codegen_ssa::common::IntPredicate;
432+
let tp_ty = substs.type_at(0);
433+
let layout = self.layout_of(tp_ty).layout;
434+
let use_integer_compare = match layout.abi {
435+
Scalar(_) | ScalarPair(_, _) => true,
436+
Uninhabited | Vector { .. } => false,
437+
Aggregate { .. } => {
438+
// For rusty ABIs, small aggregates are actually passed
439+
// as `RegKind::Integer` (see `FnAbi::adjust_for_abi`),
440+
// so we re-use that same threshold here.
441+
layout.size <= self.data_layout().pointer_size * 2
442+
}
443+
};
444+
445+
let a = args[0].immediate();
446+
let b = args[1].immediate();
447+
if layout.size.bytes() == 0 {
448+
self.const_bool(true)
449+
} else if use_integer_compare {
450+
let integer_ty = self.type_ix(layout.size.bits());
451+
let ptr_ty = self.type_ptr_to(integer_ty);
452+
let a_ptr = self.bitcast(a, ptr_ty);
453+
let a_val = self.load(integer_ty, a_ptr, layout.align.abi);
454+
let b_ptr = self.bitcast(b, ptr_ty);
455+
let b_val = self.load(integer_ty, b_ptr, layout.align.abi);
456+
self.icmp(IntPredicate::IntEQ, a_val, b_val)
457+
} else {
458+
let i8p_ty = self.type_i8p();
459+
let a_ptr = self.bitcast(a, i8p_ty);
460+
let b_ptr = self.bitcast(b, i8p_ty);
461+
let n = self.const_usize(layout.size.bytes());
462+
let intrinsic = self.get_intrinsic("memcmp");
463+
let cmp = self.call(self.type_i1(), intrinsic, &[a_ptr, b_ptr, n], None);
464+
self.icmp(IntPredicate::IntEQ, cmp, self.const_i32(0))
465+
}
466+
}
428467
// is this even supported by nvvm? i did not find a definitive answer
429468
_ if name_str.starts_with("simd_") => todo!("simd intrinsics"),
430469
_ => bug!("unknown intrinsic '{}'", name),

0 commit comments

Comments
 (0)