1
1
use std:: borrow:: { Borrow , Cow } ;
2
2
use std:: ops:: Deref ;
3
- use std:: { iter, ptr} ;
3
+ use std:: { cmp , iter, ptr} ;
4
4
5
5
pub ( crate ) mod autodiff;
6
6
@@ -1595,6 +1595,46 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
1595
1595
}
1596
1596
}
1597
1597
impl < ' a , ' ll , ' tcx > Builder < ' a , ' ll , ' tcx > {
1598
+ fn trunc_int_to_i1_vector ( & mut self , val : & ' ll Value , dest_ty : & ' ll Type ) -> & ' ll Value {
1599
+ let vector_length = self . vector_length ( dest_ty) as u64 ;
1600
+ let int_width = cmp:: max ( vector_length. next_power_of_two ( ) , 8 ) ;
1601
+
1602
+ let bitcasted = self . bitcast ( val, self . type_vector ( self . type_i1 ( ) , int_width) ) ;
1603
+ if vector_length == int_width {
1604
+ bitcasted
1605
+ } else {
1606
+ let shuffle_mask =
1607
+ ( 0 ..vector_length) . map ( |i| self . const_i32 ( i as i32 ) ) . collect :: < Vec < _ > > ( ) ;
1608
+ self . shuffle_vector ( bitcasted, bitcasted, self . const_vector ( & shuffle_mask) )
1609
+ }
1610
+ }
1611
+
1612
+ fn zext_i1_vector_to_int (
1613
+ & mut self ,
1614
+ mut val : & ' ll Value ,
1615
+ src_ty : & ' ll Type ,
1616
+ dest_ty : & ' ll Type ,
1617
+ ) -> & ' ll Value {
1618
+ let vector_length = self . vector_length ( src_ty) as u64 ;
1619
+ let int_width = cmp:: max ( vector_length. next_power_of_two ( ) , 8 ) ;
1620
+
1621
+ if vector_length != int_width {
1622
+ let shuffle_indices = match vector_length {
1623
+ 0 => unreachable ! ( "zero length vectors are not allowed" ) ,
1624
+ 1 => vec ! [ 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ,
1625
+ 2 => vec ! [ 0 , 1 , 2 , 3 , 2 , 3 , 2 , 3 ] ,
1626
+ 3 => vec ! [ 0 , 1 , 2 , 3 , 4 , 5 , 3 , 4 ] ,
1627
+ 4 .. => ( 0 ..int_width as i32 ) . collect ( ) ,
1628
+ } ;
1629
+ let shuffle_mask =
1630
+ shuffle_indices. into_iter ( ) . map ( |i| self . const_i32 ( i) ) . collect :: < Vec < _ > > ( ) ;
1631
+ val =
1632
+ self . shuffle_vector ( val, self . const_null ( src_ty) , self . const_vector ( & shuffle_mask) ) ;
1633
+ }
1634
+
1635
+ self . bitcast ( val, dest_ty)
1636
+ }
1637
+
1598
1638
fn autocast (
1599
1639
& mut self ,
1600
1640
llfn : & ' ll Value ,
@@ -1610,6 +1650,13 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
1610
1650
}
1611
1651
1612
1652
match self . type_kind ( llvm_ty) {
1653
+ TypeKind :: Vector if self . element_type ( llvm_ty) == self . type_i1 ( ) => {
1654
+ if is_argument {
1655
+ self . trunc_int_to_i1_vector ( val, dest_ty)
1656
+ } else {
1657
+ self . zext_i1_vector_to_int ( val, src_ty, dest_ty)
1658
+ }
1659
+ }
1613
1660
TypeKind :: Struct => {
1614
1661
let mut ret = self . const_poison ( dest_ty) ;
1615
1662
for ( idx, ( src_element_ty, dest_element_ty) ) in
0 commit comments