@@ -32,9 +32,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
3232 let to = layout. ty . discriminant_for_variant ( fx. tcx , variant_index) . unwrap ( ) . val ;
3333 let to = match ptr. layout ( ) . ty . kind ( ) {
3434 ty:: Uint ( UintTy :: U128 ) | ty:: Int ( IntTy :: I128 ) => {
35- let lsb = fx. bcx . ins ( ) . iconst ( types:: I64 , to as u64 as i64 ) ;
36- let msb = fx. bcx . ins ( ) . iconst ( types:: I64 , ( to >> 64 ) as u64 as i64 ) ;
37- fx. bcx . ins ( ) . iconcat ( lsb, msb)
35+ codegen_iconst_u128 ( & mut fx. bcx , to)
3836 }
3937 ty:: Uint ( _) | ty:: Int ( _) => {
4038 let clif_ty = fx. clif_type ( ptr. layout ( ) . ty ) . unwrap ( ) ;
@@ -58,12 +56,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
5856 let niche_value = variant_index. as_u32 ( ) - niche_variants. start ( ) . as_u32 ( ) ;
5957 let niche_value = ( niche_value as u128 ) . wrapping_add ( niche_start) ;
6058 let niche_value = match niche_type {
61- types:: I128 => {
62- let lsb = fx. bcx . ins ( ) . iconst ( types:: I64 , niche_value as u64 as i64 ) ;
63- let msb =
64- fx. bcx . ins ( ) . iconst ( types:: I64 , ( niche_value >> 64 ) as u64 as i64 ) ;
65- fx. bcx . ins ( ) . iconcat ( lsb, msb)
66- }
59+ types:: I128 => codegen_iconst_u128 ( & mut fx. bcx , niche_value) ,
6760 ty => fx. bcx . ins ( ) . iconst ( ty, niche_value as i64 ) ,
6861 } ;
6962 let niche_llval = CValue :: by_val ( niche_value, niche. layout ( ) ) ;
@@ -95,9 +88,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
9588
9689 let val = match dest_layout. ty . kind ( ) {
9790 ty:: Uint ( UintTy :: U128 ) | ty:: Int ( IntTy :: I128 ) => {
98- let lsb = fx. bcx . ins ( ) . iconst ( types:: I64 , discr_val as u64 as i64 ) ;
99- let msb = fx. bcx . ins ( ) . iconst ( types:: I64 , ( discr_val >> 64 ) as u64 as i64 ) ;
100- fx. bcx . ins ( ) . iconcat ( lsb, msb)
91+ codegen_iconst_u128 ( & mut fx. bcx , discr_val)
10192 }
10293 ty:: Uint ( _) | ty:: Int ( _) => {
10394 let clif_ty = fx. clif_type ( dest_layout. ty ) . unwrap ( ) ;
@@ -168,12 +159,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
168159 // The special cases don't apply, so we'll have to go with
169160 // the general algorithm.
170161 let niche_start = match fx. bcx . func . dfg . value_type ( tag) {
171- types:: I128 => {
172- let lsb = fx. bcx . ins ( ) . iconst ( types:: I64 , niche_start as u64 as i64 ) ;
173- let msb =
174- fx. bcx . ins ( ) . iconst ( types:: I64 , ( niche_start >> 64 ) as u64 as i64 ) ;
175- fx. bcx . ins ( ) . iconcat ( lsb, msb)
176- }
162+ types:: I128 => codegen_iconst_u128 ( & mut fx. bcx , niche_start) ,
177163 ty => fx. bcx . ins ( ) . iconst ( ty, niche_start as i64 ) ,
178164 } ;
179165 let relative_discr = fx. bcx . ins ( ) . isub ( tag, niche_start) ;
@@ -191,21 +177,14 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
191177 tagged_discr
192178 } else {
193179 let delta = match cast_to {
194- types:: I128 => {
195- let lsb = fx. bcx . ins ( ) . iconst ( types:: I64 , delta as u64 as i64 ) ;
196- let msb = fx. bcx . ins ( ) . iconst ( types:: I64 , ( delta >> 64 ) as u64 as i64 ) ;
197- fx. bcx . ins ( ) . iconcat ( lsb, msb)
198- }
180+ types:: I128 => codegen_iconst_u128 ( & mut fx. bcx , delta) ,
199181 ty => fx. bcx . ins ( ) . iconst ( ty, delta as i64 ) ,
200182 } ;
201183 fx. bcx . ins ( ) . iadd ( tagged_discr, delta)
202184 } ;
203185
204186 let untagged_variant = if cast_to == types:: I128 {
205- let zero = fx. bcx . ins ( ) . iconst ( types:: I64 , 0 ) ;
206- let untagged_variant =
207- fx. bcx . ins ( ) . iconst ( types:: I64 , i64:: from ( untagged_variant. as_u32 ( ) ) ) ;
208- fx. bcx . ins ( ) . iconcat ( untagged_variant, zero)
187+ codegen_iconst_u128 ( & mut fx. bcx , u128:: from ( untagged_variant. as_u32 ( ) ) )
209188 } else {
210189 fx. bcx . ins ( ) . iconst ( cast_to, i64:: from ( untagged_variant. as_u32 ( ) ) )
211190 } ;
0 commit comments