@@ -1597,20 +1597,42 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
1597
1597
unimplemented ! ( ) ;
1598
1598
}
1599
1599
1600
-
1601
1600
pub fn vector_select ( & mut self , cond : RValue < ' gcc > , then_val : RValue < ' gcc > , else_val : RValue < ' gcc > ) -> RValue < ' gcc > {
1602
1601
// cond is a vector of integers, not of bools.
1603
- let cond_type = cond. get_type ( ) ;
1604
- let vector_type = cond_type. unqualified ( ) . dyncast_vector ( ) . expect ( "vector type" ) ;
1602
+ let vector_type = cond. get_type ( ) . unqualified ( ) . dyncast_vector ( ) . expect ( "vector type" ) ;
1605
1603
let num_units = vector_type. get_num_units ( ) ;
1606
1604
let element_type = vector_type. get_element_type ( ) ;
1605
+
1606
+ #[ cfg( feature="master" ) ]
1607
+ let ( cond, element_type) = {
1608
+ let then_val_vector_type = then_val. get_type ( ) . dyncast_vector ( ) . expect ( "vector type" ) ;
1609
+ let then_val_element_type = then_val_vector_type. get_element_type ( ) ;
1610
+ let then_val_element_size = then_val_element_type. get_size ( ) ;
1611
+
1612
+ // NOTE: the mask needs to be of the same size as the other arguments in order for the &
1613
+ // operation to work.
1614
+ if then_val_element_size != element_type. get_size ( ) {
1615
+ let new_element_type = self . type_ix ( then_val_element_size as u64 * 8 ) ;
1616
+ let new_vector_type = self . context . new_vector_type ( new_element_type, num_units as u64 ) ;
1617
+ let cond = self . context . convert_vector ( None , cond, new_vector_type) ;
1618
+ ( cond, new_element_type)
1619
+ }
1620
+ else {
1621
+ ( cond, element_type)
1622
+ }
1623
+ } ;
1624
+
1625
+ let cond_type = cond. get_type ( ) ;
1626
+
1607
1627
let zeros = vec ! [ self . context. new_rvalue_zero( element_type) ; num_units] ;
1608
1628
let zeros = self . context . new_rvalue_from_vector ( None , cond_type, & zeros) ;
1609
1629
1630
+ let result_type = then_val. get_type ( ) ;
1631
+
1610
1632
let masks = self . context . new_comparison ( None , ComparisonOp :: NotEquals , cond, zeros) ;
1611
1633
// NOTE: masks is a vector of integers, but the values can be vectors of floats, so use bitcast to make
1612
1634
// the & operation work.
1613
- let masks = self . bitcast_if_needed ( masks , then_val . get_type ( ) ) ;
1635
+ let then_val = self . bitcast_if_needed ( then_val , masks . get_type ( ) ) ;
1614
1636
let then_vals = masks & then_val;
1615
1637
1616
1638
let minus_ones = vec ! [ self . context. new_rvalue_from_int( element_type, -1 ) ; num_units] ;
@@ -1623,7 +1645,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
1623
1645
let else_val = self . context . new_bitcast ( None , else_val, then_val. get_type ( ) ) ;
1624
1646
let else_vals = inverted_masks & else_val;
1625
1647
1626
- then_vals | else_vals
1648
+ let res = then_vals | else_vals;
1649
+ self . bitcast_if_needed ( res, result_type)
1627
1650
}
1628
1651
}
1629
1652
0 commit comments