diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-08-02 12:45:52 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2023-08-06 15:47:40 -0700 |
| commit | 502af03445f045dade14f14e754803f02c2c5e24 (patch) | |
| tree | fbeb208e1c6d7df46431f1412404e8b48dfd5349 /compiler/rustc_codegen_llvm/src | |
| parent | 85fbb571497d13cfb828de9b0d3e78656b9203c1 (diff) | |
| download | rust-502af03445f045dade14f14e754803f02c2c5e24.tar.gz rust-502af03445f045dade14f14e754803f02c2c5e24.zip | |
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/context.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/intrinsic.rs | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 3577fb2d951..2d23be6cd52 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -891,7 +891,8 @@ impl<'ll> CodegenCx<'ll, '_> { ifn!("llvm.prefetch", fn(ptr, t_i32, t_i32, t_i32) -> void); // This isn't an "LLVM intrinsic", but LLVM's optimization passes - // recognize it like one and we assume it exists in `core::slice::cmp` + // recognize it like one (including turning it into `bcmp` sometimes) + // and we use it to implement intrinsics like `raw_eq` and `compare_bytes` match self.sess().target.arch.as_ref() { "avr" | "msp430" => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i16), _ => ifn!("memcmp", fn(ptr, ptr, t_isize) -> t_i32), diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 6f1e4c5178a..4e86094ce3b 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -329,6 +329,15 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { } } + sym::compare_bytes => { + let cmp = self.call_intrinsic( + "memcmp", + &[args[0].immediate(), args[1].immediate(), args[2].immediate()], + ); + // Some targets have `memcmp` returning `i16`, but the intrinsic is always `i32`. + self.sext(cmp, self.type_ix(32)) + } + sym::black_box => { args[0].val.store(self, result); let result_val_span = [result.llval]; |
