@@ -3,7 +3,7 @@ use std::cmp;
33use libc:: c_uint;
44use rustc_abi:: {
55 ArmCall , BackendRepr , CanonAbi , HasDataLayout , InterruptKind , Primitive , Reg , RegKind , Size ,
6- X86Call ,
6+ VectorElemKind , X86Call ,
77} ;
88use rustc_codegen_ssa:: MemFlags ;
99use rustc_codegen_ssa:: mir:: operand:: { OperandRef , OperandValue } ;
@@ -137,7 +137,27 @@ impl LlvmType for Reg {
137137 128 => cx. type_f128 ( ) ,
138138 _ => bug ! ( "unsupported float: {:?}" , self ) ,
139139 } ,
140- RegKind :: Vector => cx. type_vector ( cx. type_i8 ( ) , self . size . bytes ( ) ) ,
140+ RegKind :: Vector { hint_vector_elem } => {
141+ // NOTE: it is valid to ignore the element type hint (and always pick i8).
142+ // But providing a more accurate type means fewer casts in LLVM IR,
143+ // which helps with optimization.
144+ let ( ty, bytes) = match hint_vector_elem {
145+ VectorElemKind :: I8 => ( cx. type_ix ( 8 ) , 1 ) ,
146+ VectorElemKind :: I16 => ( cx. type_ix ( 16 ) , 2 ) ,
147+ VectorElemKind :: I32 => ( cx. type_ix ( 32 ) , 4 ) ,
148+ VectorElemKind :: I64 => ( cx. type_ix ( 64 ) , 8 ) ,
149+ VectorElemKind :: I128 => ( cx. type_ix ( 128 ) , 16 ) ,
150+ VectorElemKind :: F16 => ( cx. type_f16 ( ) , 2 ) ,
151+ VectorElemKind :: F32 => ( cx. type_f32 ( ) , 4 ) ,
152+ VectorElemKind :: F64 => ( cx. type_f64 ( ) , 8 ) ,
153+ VectorElemKind :: F128 => ( cx. type_f128 ( ) , 16 ) ,
154+ VectorElemKind :: Ptr => {
155+ ( cx. type_ptr ( ) , cx. tcx . data_layout . pointer_size ( ) . bytes ( ) )
156+ }
157+ } ;
158+
159+ cx. type_vector ( ty, self . size . bytes ( ) / bytes)
160+ }
141161 }
142162 }
143163}
0 commit comments