Skip to content

Commit 506c507

Browse files
authored
Unrolled build for #144455
Rollup merge of #144455 - TDecking:ctlz-cttz, r=SparrowLii Unify LLVM ctlz/cttz intrinsic generation The type signature for `llvm.ctlz` is the same as the one for `llvm.cttz`, which enables a small simplification.
2 parents 86ef320 + 948c795 commit 506c507

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -382,26 +382,16 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
382382
let width = size.bits();
383383
let llty = self.type_ix(width);
384384
match name {
385-
sym::ctlz | sym::cttz => {
386-
let y = self.const_bool(false);
387-
let ret = self.call_intrinsic(
388-
format!("llvm.{name}"),
389-
&[llty],
390-
&[args[0].immediate(), y],
391-
);
392-
393-
self.intcast(ret, result.layout.llvm_type(self), false)
394-
}
395-
sym::ctlz_nonzero => {
396-
let y = self.const_bool(true);
397-
let ret =
398-
self.call_intrinsic("llvm.ctlz", &[llty], &[args[0].immediate(), y]);
399-
self.intcast(ret, result.layout.llvm_type(self), false)
400-
}
401-
sym::cttz_nonzero => {
402-
let y = self.const_bool(true);
385+
sym::ctlz | sym::ctlz_nonzero | sym::cttz | sym::cttz_nonzero => {
386+
let y =
387+
self.const_bool(name == sym::ctlz_nonzero || name == sym::cttz_nonzero);
388+
let llvm_name = if name == sym::ctlz || name == sym::ctlz_nonzero {
389+
"llvm.ctlz"
390+
} else {
391+
"llvm.cttz"
392+
};
403393
let ret =
404-
self.call_intrinsic("llvm.cttz", &[llty], &[args[0].immediate(), y]);
394+
self.call_intrinsic(llvm_name, &[llty], &[args[0].immediate(), y]);
405395
self.intcast(ret, result.layout.llvm_type(self), false)
406396
}
407397
sym::ctpop => {

0 commit comments

Comments
 (0)