diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-05-30 10:25:41 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2021-07-08 14:55:54 -0700 |
| commit | 2456495a260827217d3c612d6c577c2f165c61eb (patch) | |
| tree | e85ffd47a15f93a5b6f0a6324bb8b747659a2448 /compiler/rustc_mir | |
| parent | d05eafae2fcc05bd64ab094a1352a5c16df3106e (diff) | |
| download | rust-2456495a260827217d3c612d6c577c2f165c61eb.tar.gz rust-2456495a260827217d3c612d6c577c2f165c61eb.zip | |
Stop generating `alloca`s+`memcmp` for simple array equality
Diffstat (limited to 'compiler/rustc_mir')
| -rw-r--r-- | compiler/rustc_mir/src/interpret/intrinsics.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_mir/src/interpret/intrinsics.rs b/compiler/rustc_mir/src/interpret/intrinsics.rs index 4e4166dad50..5dd679b8912 100644 --- a/compiler/rustc_mir/src/interpret/intrinsics.rs +++ b/compiler/rustc_mir/src/interpret/intrinsics.rs @@ -472,6 +472,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { throw_ub_format!("`assume` intrinsic called with `false`"); } } + sym::raw_eq => { + let result = self.raw_eq_intrinsic(&args[0], &args[1])?; + self.write_scalar(result, dest)?; + } _ => return Ok(false), } @@ -559,4 +563,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { self.memory.copy(src, align, dst, align, size, nonoverlapping) } + + pub(crate) fn raw_eq_intrinsic( + &mut self, + lhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>, + rhs: &OpTy<'tcx, <M as Machine<'mir, 'tcx>>::PointerTag>, + ) -> InterpResult<'tcx, Scalar<M::PointerTag>> { + let layout = self.layout_of(lhs.layout.ty.builtin_deref(true).unwrap().ty)?; + + let lhs = self.read_scalar(lhs)?.check_init()?; + let rhs = self.read_scalar(rhs)?.check_init()?; + let lhs_bytes = self.memory.read_bytes(lhs, layout.size)?; + let rhs_bytes = self.memory.read_bytes(rhs, layout.size)?; + Ok(Scalar::Int((lhs_bytes == rhs_bytes).into())) + } } |
