@@ -1791,14 +1791,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1791
1791
// nightlies - and that PR happens to remove the last GEP that can be
1792
1792
// emitted with any "structured" (struct/array) indices, beyond the
1793
1793
// "first index" (which acts as `<*T>::offset` aka "pointer arithmetic").
1794
- if let & [ ptr_base_index, structured_index] = indices {
1795
- if self . builder . lookup_const_scalar ( ptr_base_index) == Some ( 0 ) {
1796
- if let SpirvType :: Array { element, .. } | SpirvType :: RuntimeArray { element, .. } =
1797
- self . lookup_type ( ty)
1798
- {
1799
- return self . maybe_inbounds_gep ( element, ptr, & [ structured_index] , true ) ;
1800
- }
1801
- }
1794
+ if let & [ ptr_base_index, structured_index] = indices
1795
+ && self . builder . lookup_const_scalar ( ptr_base_index) == Some ( 0 )
1796
+ && let SpirvType :: Array { element, .. } | SpirvType :: RuntimeArray { element, .. } =
1797
+ self . lookup_type ( ty)
1798
+ {
1799
+ return self . maybe_inbounds_gep ( element, ptr, & [ structured_index] , true ) ;
1802
1800
}
1803
1801
1804
1802
self . maybe_inbounds_gep ( ty, ptr, indices, true )
@@ -1883,22 +1881,20 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1883
1881
// capabilities. For example, casting a f16 constant to f32 will directly
1884
1882
// create a f32 constant, avoiding the need for Float16 capability if it is
1885
1883
// not used elsewhere.
1886
- if let Some ( const_val) = self . builder . lookup_const_scalar ( val) {
1887
- if let ( SpirvType :: Float ( src_width) , SpirvType :: Float ( dst_width) ) =
1884
+ if let Some ( const_val) = self . builder . lookup_const_scalar ( val)
1885
+ && let ( SpirvType :: Float ( src_width) , SpirvType :: Float ( dst_width) ) =
1888
1886
( self . lookup_type ( val. ty ) , self . lookup_type ( dest_ty) )
1889
- {
1890
- if src_width < dst_width {
1891
- // Convert the bit representation to the actual float value
1892
- let float_val = match src_width {
1893
- 32 => Some ( f32:: from_bits ( const_val as u32 ) as f64 ) ,
1894
- 64 => Some ( f64:: from_bits ( const_val as u64 ) ) ,
1895
- _ => None ,
1896
- } ;
1887
+ && src_width < dst_width
1888
+ {
1889
+ // Convert the bit representation to the actual float value
1890
+ let float_val = match src_width {
1891
+ 32 => Some ( f32:: from_bits ( const_val as u32 ) as f64 ) ,
1892
+ 64 => Some ( f64:: from_bits ( const_val as u64 ) ) ,
1893
+ _ => None ,
1894
+ } ;
1897
1895
1898
- if let Some ( val) = float_val {
1899
- return self . constant_float ( dest_ty, val) ;
1900
- }
1901
- }
1896
+ if let Some ( val) = float_val {
1897
+ return self . constant_float ( dest_ty, val) ;
1902
1898
}
1903
1899
}
1904
1900
@@ -3105,14 +3101,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3105
3101
let const_slice_as_elem_ids = |ptr_id : Word , len : usize | {
3106
3102
if let SpirvConst :: PtrTo { pointee } =
3107
3103
self . builder . lookup_const_by_id ( ptr_id) ?
3108
- {
3109
- if let SpirvConst :: Composite ( elems) =
3104
+ && let SpirvConst :: Composite ( elems) =
3110
3105
self . builder . lookup_const_by_id ( pointee) ?
3111
- {
3112
- if elems. len ( ) == len {
3113
- return Some ( elems) ;
3114
- }
3115
- }
3106
+ && elems. len ( ) == len
3107
+ {
3108
+ return Some ( elems) ;
3116
3109
}
3117
3110
None
3118
3111
} ;
@@ -3147,12 +3140,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3147
3140
] = args[ ..]
3148
3141
{
3149
3142
// Optional `&'static panic::Location<'static>`.
3150
- if other_args. len ( ) <= 1 {
3151
- if let Some ( const_msg) = const_str_as_utf8 ( & [ a_id, b_id] ) {
3152
- decoded_format_args. const_pieces =
3153
- Some ( [ const_msg] . into_iter ( ) . collect ( ) ) ;
3154
- return Ok ( decoded_format_args) ;
3155
- }
3143
+ if other_args. len ( ) <= 1
3144
+ && let Some ( const_msg) = const_str_as_utf8 ( & [ a_id, b_id] )
3145
+ {
3146
+ decoded_format_args. const_pieces = Some ( [ const_msg] . into_iter ( ) . collect ( ) ) ;
3147
+ return Ok ( decoded_format_args) ;
3156
3148
}
3157
3149
}
3158
3150
@@ -3267,12 +3259,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3267
3259
}
3268
3260
3269
3261
// HACK(eddyb) avoid the logic below that assumes only ID operands
3270
- if inst. class . opcode == Op :: CompositeExtract {
3271
- if let ( Some ( r) , & [ Operand :: IdRef ( x) , Operand :: LiteralBit32 ( i) ] ) =
3262
+ if inst. class . opcode == Op :: CompositeExtract
3263
+ && let ( Some ( r) , & [ Operand :: IdRef ( x) , Operand :: LiteralBit32 ( i) ] ) =
3272
3264
( inst. result_id , & inst. operands [ ..] )
3273
- {
3274
- return Some ( Inst :: CompositeExtract ( r, x, i) ) ;
3275
- }
3265
+ {
3266
+ return Some ( Inst :: CompositeExtract ( r, x, i) ) ;
3276
3267
}
3277
3268
3278
3269
// HACK(eddyb) all instructions accepted below
@@ -3483,8 +3474,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3483
3474
// access chain cases that `inbounds_gep` can now cause.
3484
3475
if let Inst :: InBoundsAccessChain ( dst_field_ptr, dst_base_ptr, 0 ) =
3485
3476
copy_to_rt_args_array_insts[ 0 ]
3486
- {
3487
- if let Some ( mut prev_insts) = try_rev_take ( 1 ) {
3477
+ && let Some ( mut prev_insts) = try_rev_take ( 1 ) {
3488
3478
assert_eq ! ( prev_insts. len( ) , 1 ) ;
3489
3479
let prev_inst = prev_insts. pop ( ) . unwrap ( ) ;
3490
3480
@@ -3503,7 +3493,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3503
3493
}
3504
3494
}
3505
3495
}
3506
- }
3507
3496
3508
3497
match copy_to_rt_args_array_insts[ ..] {
3509
3498
[
@@ -3855,27 +3844,27 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
3855
3844
// Since From is only implemented for safe conversions (widening conversions that preserve
3856
3845
// the numeric value), we can directly create a constant of the target type for primitive
3857
3846
// numeric types.
3858
- if let [ arg] = args {
3859
- if let Some ( const_val) = self . builder . lookup_const_scalar ( * arg) {
3860
- use rustc_middle:: ty:: FloatTy ;
3861
- let optimized_result = match ( source_ty. kind ( ) , target_ty. kind ( ) ) {
3862
- // Integer widening conversions
3863
- ( ty:: Uint ( _) , ty:: Uint ( _) ) | ( ty:: Int ( _) , ty:: Int ( _) ) => {
3864
- Some ( self . constant_int ( result_type, const_val) )
3865
- }
3866
- // Float widening conversions
3867
- // TODO(@LegNeato): Handle more float types
3868
- ( ty:: Float ( FloatTy :: F32 ) , ty:: Float ( FloatTy :: F64 ) ) => {
3869
- let float_val = f32:: from_bits ( const_val as u32 ) as f64 ;
3870
- Some ( self . constant_float ( result_type, float_val) )
3871
- }
3872
- // No optimization for narrowing conversions or unsupported types
3873
- _ => None ,
3874
- } ;
3875
-
3876
- if let Some ( result) = optimized_result {
3877
- return result;
3847
+ if let [ arg] = args
3848
+ && let Some ( const_val) = self . builder . lookup_const_scalar ( * arg)
3849
+ {
3850
+ use rustc_middle:: ty:: FloatTy ;
3851
+ let optimized_result = match ( source_ty. kind ( ) , target_ty. kind ( ) ) {
3852
+ // Integer widening conversions
3853
+ ( ty:: Uint ( _) , ty:: Uint ( _) ) | ( ty:: Int ( _) , ty:: Int ( _) ) => {
3854
+ Some ( self . constant_int ( result_type, const_val) )
3878
3855
}
3856
+ // Float widening conversions
3857
+ // TODO(@LegNeato): Handle more float types
3858
+ ( ty:: Float ( FloatTy :: F32 ) , ty:: Float ( FloatTy :: F64 ) ) => {
3859
+ let float_val = f32:: from_bits ( const_val as u32 ) as f64 ;
3860
+ Some ( self . constant_float ( result_type, float_val) )
3861
+ }
3862
+ // No optimization for narrowing conversions or unsupported types
3863
+ _ => None ,
3864
+ } ;
3865
+
3866
+ if let Some ( result) = optimized_result {
3867
+ return result;
3879
3868
}
3880
3869
}
3881
3870
}
0 commit comments