@@ -26,6 +26,7 @@ use rustc_span::source_map::Spanned;
2626use rustc_span:: symbol:: { sym, Symbol } ;
2727
2828pub ( crate ) use self :: llvm:: codegen_llvm_intrinsic_call;
29+ use crate :: cast:: clif_intcast;
2930use crate :: prelude:: * ;
3031
3132fn bug_on_incorrect_arg_count ( intrinsic : impl std:: fmt:: Display ) -> ! {
@@ -627,7 +628,8 @@ fn codegen_regular_intrinsic_call<'tcx>(
627628
628629 // FIXME trap on `ctlz_nonzero` with zero arg.
629630 let res = fx. bcx . ins ( ) . clz ( val) ;
630- let res = CValue :: by_val ( res, arg. layout ( ) ) ;
631+ let res = clif_intcast ( fx, res, types:: I32 , false ) ;
632+ let res = CValue :: by_val ( res, ret. layout ( ) ) ;
631633 ret. write_cvalue ( fx, res) ;
632634 }
633635 sym:: cttz | sym:: cttz_nonzero => {
@@ -636,15 +638,17 @@ fn codegen_regular_intrinsic_call<'tcx>(
636638
637639 // FIXME trap on `cttz_nonzero` with zero arg.
638640 let res = fx. bcx . ins ( ) . ctz ( val) ;
639- let res = CValue :: by_val ( res, arg. layout ( ) ) ;
641+ let res = clif_intcast ( fx, res, types:: I32 , false ) ;
642+ let res = CValue :: by_val ( res, ret. layout ( ) ) ;
640643 ret. write_cvalue ( fx, res) ;
641644 }
642645 sym:: ctpop => {
643646 intrinsic_args ! ( fx, args => ( arg) ; intrinsic) ;
644647 let val = arg. load_scalar ( fx) ;
645648
646649 let res = fx. bcx . ins ( ) . popcnt ( val) ;
647- let res = CValue :: by_val ( res, arg. layout ( ) ) ;
650+ let res = clif_intcast ( fx, res, types:: I32 , false ) ;
651+ let res = CValue :: by_val ( res, ret. layout ( ) ) ;
648652 ret. write_cvalue ( fx, res) ;
649653 }
650654 sym:: bitreverse => {
0 commit comments