about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-08-07 05:06:51 +0000
committerbors <bors@rust-lang.org>2023-08-07 05:06:51 +0000
commit4a71a05d52a534c18fed8b1415c4858570d8ef86 (patch)
tree8e47b2aab776326b07b737457be1238f4e60b254 /compiler/rustc_codegen_llvm/src
parent9fca8e7517fd714685de8e580d8e0e08073c8e16 (diff)
parentd804b74c6cd65549c826d2207c4bdaffdd9bf30d (diff)
downloadrust-4a71a05d52a534c18fed8b1415c4858570d8ef86.tar.gz
rust-4a71a05d52a534c18fed8b1415c4858570d8ef86.zip
Auto merge of #114569 - matthiaskrgr:rollup-p8tcxtz, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #98935 (Implement `Option::take_if`)
 - #114093 (Add regression test for `echo 'mod unknown;' | rustc -`)
 - #114229 (Nest tests/codegen/sanitizer*.rs tests in sanitizer dir)
 - #114230 (Nest other codegen test topics)
 - #114362 (string.rs: remove "Basic usage" text)
 - #114365 (str.rs: remove "Basic usage" text)
 - #114382 (Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly)
 - #114549 (Style fix and refactor on resolve diagnostics)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
-rw-r--r--compiler/rustc_codegen_llvm/src/context.rs3
-rw-r--r--compiler/rustc_codegen_llvm/src/intrinsic.rs10
2 files changed, 12 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..a9b06030e70 100644
--- a/compiler/rustc_codegen_llvm/src/intrinsic.rs
+++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs
@@ -329,6 +329,16 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
                 }
             }
 
+            sym::compare_bytes => {
+                // Here we assume that the `memcmp` provided by the target is a NOP for size 0.
+                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];