Skip to content

Commit 4e0ee2a

Browse files
committed
Avoid a couple of Symbol::as_str calls in cg_llvm
1 parent 9886c23 commit 4e0ee2a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
9696
let arg_tys = sig.inputs();
9797
let ret_ty = sig.output();
9898
let name = tcx.item_name(def_id);
99-
let name_str = &*name.as_str();
10099

101100
let llret_ty = self.layout_of(ret_ty).llvm_type(self);
102101
let result = PlaceRef::new_sized(llresult, fn_abi.ret.layout);
@@ -230,9 +229,14 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
230229
&[args[0].immediate(), y],
231230
)
232231
}
233-
sym::ctlz_nonzero | sym::cttz_nonzero => {
232+
sym::ctlz_nonzero => {
234233
let y = self.const_bool(true);
235-
let llvm_name = &format!("llvm.{}.i{}", &name_str[..4], width);
234+
let llvm_name = &format!("llvm.ctlz.i{}", width);
235+
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
236+
}
237+
sym::cttz_nonzero => {
238+
let y = self.const_bool(true);
239+
let llvm_name = &format!("llvm.cttz.i{}", width);
236240
self.call_intrinsic(llvm_name, &[args[0].immediate(), y])
237241
}
238242
sym::ctpop => self.call_intrinsic(
@@ -353,7 +357,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
353357
return;
354358
}
355359

356-
_ if name_str.starts_with("simd_") => {
360+
_ if name.as_str().starts_with("simd_") => {
357361
match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) {
358362
Ok(llval) => llval,
359363
Err(()) => return,
@@ -843,7 +847,6 @@ fn generic_simd_intrinsic(
843847
let sig =
844848
tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), callee_ty.fn_sig(tcx));
845849
let arg_tys = sig.inputs();
846-
let name_str = &*name.as_str();
847850

848851
if name == sym::simd_select_bitmask {
849852
let in_ty = arg_tys[0];
@@ -917,7 +920,7 @@ fn generic_simd_intrinsic(
917920
));
918921
}
919922

920-
if let Some(stripped) = name_str.strip_prefix("simd_shuffle") {
923+
if let Some(stripped) = name.as_str().strip_prefix("simd_shuffle") {
921924
// If this intrinsic is the older "simd_shuffleN" form, simply parse the integer.
922925
// If there is no suffix, use the index array length.
923926
let n: u64 = if stripped.is_empty() {

0 commit comments

Comments
 (0)