@@ -1791,14 +1791,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
17911791 // nightlies - and that PR happens to remove the last GEP that can be
17921792 // emitted with any "structured" (struct/array) indices, beyond the
17931793 // "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 ) ;
18021800 }
18031801
18041802 self . maybe_inbounds_gep ( ty, ptr, indices, true )
@@ -1883,22 +1881,20 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
18831881 // capabilities. For example, casting a f16 constant to f32 will directly
18841882 // create a f32 constant, avoiding the need for Float16 capability if it is
18851883 // 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) ) =
18881886 ( 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+ } ;
18971895
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) ;
19021898 }
19031899 }
19041900
@@ -3105,14 +3101,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
31053101 let const_slice_as_elem_ids = |ptr_id : Word , len : usize | {
31063102 if let SpirvConst :: PtrTo { pointee } =
31073103 self . builder . lookup_const_by_id ( ptr_id) ?
3108- {
3109- if let SpirvConst :: Composite ( elems) =
3104+ && let SpirvConst :: Composite ( elems) =
31103105 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) ;
31163109 }
31173110 None
31183111 } ;
@@ -3147,12 +3140,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
31473140 ] = args[ ..]
31483141 {
31493142 // 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) ;
31563148 }
31573149 }
31583150
@@ -3267,12 +3259,11 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
32673259 }
32683260
32693261 // 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) ] ) =
32723264 ( inst. result_id , & inst. operands [ ..] )
3273- {
3274- return Some ( Inst :: CompositeExtract ( r, x, i) ) ;
3275- }
3265+ {
3266+ return Some ( Inst :: CompositeExtract ( r, x, i) ) ;
32763267 }
32773268
32783269 // HACK(eddyb) all instructions accepted below
@@ -3483,8 +3474,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
34833474 // access chain cases that `inbounds_gep` can now cause.
34843475 if let Inst :: InBoundsAccessChain ( dst_field_ptr, dst_base_ptr, 0 ) =
34853476 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 ) {
34883478 assert_eq ! ( prev_insts. len( ) , 1 ) ;
34893479 let prev_inst = prev_insts. pop ( ) . unwrap ( ) ;
34903480
@@ -3503,7 +3493,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
35033493 }
35043494 }
35053495 }
3506- }
35073496
35083497 match copy_to_rt_args_array_insts[ ..] {
35093498 [
@@ -3855,27 +3844,27 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
38553844 // Since From is only implemented for safe conversions (widening conversions that preserve
38563845 // the numeric value), we can directly create a constant of the target type for primitive
38573846 // 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) )
38783855 }
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;
38793868 }
38803869 }
38813870 }
0 commit comments