Skip to content

Commit 2549e8a

Browse files
committed
Add LLVM backend support for funnel shifts
1 parent 9b22e90 commit 2549e8a

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
383383
| sym::rotate_left
384384
| sym::rotate_right
385385
| sym::saturating_add
386-
| sym::saturating_sub => {
386+
| sym::saturating_sub
387+
| sym::unchecked_funnel_shl
388+
| sym::unchecked_funnel_shr => {
387389
let ty = args[0].layout.ty;
388390
if !ty.is_integral() {
389391
tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
@@ -437,6 +439,19 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
437439

438440
self.call_intrinsic(llvm_name, &[llty], &[val, val, raw_shift])
439441
}
442+
sym::unchecked_funnel_shl | sym::unchecked_funnel_shr => {
443+
let is_left = name == sym::unchecked_funnel_shl;
444+
let lhs = args[0].immediate();
445+
let rhs = args[1].immediate();
446+
let raw_shift = args[2].immediate();
447+
let llvm_name = format!("llvm.fsh{}", if is_left { 'l' } else { 'r' });
448+
449+
// llvm expects shift to be the same type as the values, but rust
450+
// always uses `u32`.
451+
let raw_shift = self.intcast(raw_shift, self.val_ty(lhs), false);
452+
453+
self.call_intrinsic(llvm_name, &[llty], &[lhs, rhs, raw_shift])
454+
}
440455
sym::saturating_add | sym::saturating_sub => {
441456
let is_add = name == sym::saturating_add;
442457
let lhs = args[0].immediate();

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ pub(crate) fn check_intrinsic_type(
449449
}
450450
sym::unchecked_shl | sym::unchecked_shr => (2, 0, vec![param(0), param(1)], param(0)),
451451
sym::rotate_left | sym::rotate_right => (1, 0, vec![param(0), tcx.types.u32], param(0)),
452+
sym::unchecked_funnel_shl | sym::unchecked_funnel_shr => {
453+
(1, 0, vec![param(0), param(0), tcx.types.u32], param(0))
454+
}
452455
sym::unchecked_add | sym::unchecked_sub | sym::unchecked_mul => {
453456
(1, 0, vec![param(0), param(0)], param(0))
454457
}

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,8 @@ symbols! {
22692269
unboxed_closures,
22702270
unchecked_add,
22712271
unchecked_div,
2272+
unchecked_funnel_shl,
2273+
unchecked_funnel_shr,
22722274
unchecked_mul,
22732275
unchecked_rem,
22742276
unchecked_shl,

0 commit comments

Comments
 (0)