@@ -220,12 +220,12 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
220220 let after_block = func. new_block ( "after" ) ;
221221
222222 let arg = args[ 0 ] . immediate ( ) ;
223- let result = func. new_local ( None , arg . get_type ( ) , "zeros" ) ;
223+ let result = func. new_local ( None , self . u32_type , "zeros" ) ;
224224 let zero = self . cx . gcc_zero ( arg. get_type ( ) ) ;
225225 let cond = self . gcc_icmp ( IntPredicate :: IntEQ , arg, zero) ;
226226 self . llbb ( ) . end_with_conditional ( None , cond, then_block, else_block) ;
227227
228- let zero_result = self . cx . gcc_uint ( arg . get_type ( ) , width) ;
228+ let zero_result = self . cx . gcc_uint ( self . u32_type , width) ;
229229 then_block. add_assignment ( None , result, zero_result) ;
230230 then_block. end_with_jump ( None , after_block) ;
231231
@@ -709,6 +709,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
709709 fn count_leading_zeroes ( & mut self , width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
710710 // TODO(antoyo): use width?
711711 let arg_type = arg. get_type ( ) ;
712+ let result_type = self . u32_type ;
712713 let count_leading_zeroes =
713714 // TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here
714715 // instead of using is_uint().
@@ -766,30 +767,30 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
766767
767768 let res = self . context . new_array_access ( self . location , result, index) ;
768769
769- return self . gcc_int_cast ( res. to_rvalue ( ) , arg_type ) ;
770+ return self . gcc_int_cast ( res. to_rvalue ( ) , result_type ) ;
770771 }
771772 else {
772773 let count_leading_zeroes = self . context . get_builtin_function ( "__builtin_clzll" ) ;
773774 let arg = self . context . new_cast ( self . location , arg, self . ulonglong_type ) ;
774775 let diff = self . ulonglong_type . get_size ( ) as i64 - arg_type. get_size ( ) as i64 ;
775776 let diff = self . context . new_rvalue_from_long ( self . int_type , diff * 8 ) ;
776777 let res = self . context . new_call ( self . location , count_leading_zeroes, & [ arg] ) - diff;
777- return self . context . new_cast ( self . location , res, arg_type ) ;
778+ return self . context . new_cast ( self . location , res, result_type ) ;
778779 } ;
779780 let count_leading_zeroes = self . context . get_builtin_function ( count_leading_zeroes) ;
780781 let res = self . context . new_call ( self . location , count_leading_zeroes, & [ arg] ) ;
781- self . context . new_cast ( self . location , res, arg_type )
782+ self . context . new_cast ( self . location , res, result_type )
782783 }
783784
784785 fn count_trailing_zeroes ( & mut self , _width : u64 , arg : RValue < ' gcc > ) -> RValue < ' gcc > {
785- let result_type = arg. get_type ( ) ;
786- let arg = if result_type. is_signed ( self . cx ) {
787- let new_type = result_type. to_unsigned ( self . cx ) ;
786+ let arg_type = arg. get_type ( ) ;
787+ let result_type = self . u32_type ;
788+ let arg = if arg_type. is_signed ( self . cx ) {
789+ let new_type = arg_type. to_unsigned ( self . cx ) ;
788790 self . gcc_int_cast ( arg, new_type)
789791 } else {
790792 arg
791793 } ;
792- let arg_type = arg. get_type ( ) ;
793794 let ( count_trailing_zeroes, expected_type) =
794795 // TODO(antoyo): write a new function Type::is_compatible_with(&Type) and use it here
795796 // instead of using is_uint().
@@ -874,14 +875,12 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
874875
875876 fn pop_count ( & mut self , value : RValue < ' gcc > ) -> RValue < ' gcc > {
876877 // TODO(antoyo): use the optimized version with fewer operations.
877- let result_type = value. get_type ( ) ;
878- let value_type = result_type. to_unsigned ( self . cx ) ;
878+ let result_type = self . u32_type ;
879+ let arg_type = value. get_type ( ) ;
880+ let value_type = arg_type. to_unsigned ( self . cx ) ;
879881
880- let value = if result_type. is_signed ( self . cx ) {
881- self . gcc_int_cast ( value, value_type)
882- } else {
883- value
884- } ;
882+ let value =
883+ if arg_type. is_signed ( self . cx ) { self . gcc_int_cast ( value, value_type) } else { value } ;
885884
886885 // only break apart 128-bit ints if they're not natively supported
887886 // TODO(antoyo): remove this if/when native 128-bit integers land in libgccjit
0 commit comments