@@ -1465,9 +1465,12 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1465
1465
. size ( self )
1466
1466
. align_to ( b. primitive ( ) . align ( self ) . abi ) ;
1467
1467
1468
- let pair_ty = place. layout . spirv_type ( self . span ( ) , self ) ;
1469
1468
let mut load = |i, scalar : Scalar , align| {
1470
- let llptr = self . struct_gep ( pair_ty, place. llval , i as u64 ) ;
1469
+ let llptr = if i == 0 {
1470
+ place. llval
1471
+ } else {
1472
+ self . inbounds_ptradd ( place. llval , self . const_usize ( b_offset. bytes ( ) ) )
1473
+ } ;
1471
1474
let load = self . load (
1472
1475
self . scalar_pair_element_backend_type ( place. layout , i, false ) ,
1473
1476
llptr,
@@ -1581,79 +1584,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
1581
1584
self . maybe_inbounds_gep ( ty, ptr, indices, true )
1582
1585
}
1583
1586
1584
- fn struct_gep ( & mut self , ty : Self :: Type , ptr : Self :: Value , idx : u64 ) -> Self :: Value {
1585
- let ( offset, result_pointee_type) = match self . lookup_type ( ty) {
1586
- SpirvType :: Adt {
1587
- field_offsets,
1588
- field_types,
1589
- ..
1590
- } => ( field_offsets[ idx as usize ] , field_types[ idx as usize ] ) ,
1591
- SpirvType :: Array { element, .. }
1592
- | SpirvType :: RuntimeArray { element, .. }
1593
- | SpirvType :: Vector { element, .. }
1594
- | SpirvType :: Matrix { element, .. } => (
1595
- self . lookup_type ( element) . sizeof ( self ) . unwrap ( ) * idx,
1596
- element,
1597
- ) ,
1598
- SpirvType :: InterfaceBlock { inner_type } => {
1599
- assert_eq ! ( idx, 0 ) ;
1600
- ( Size :: ZERO , inner_type)
1601
- }
1602
- other => self . fatal ( format ! (
1603
- "struct_gep not on struct, array, or vector type: {other:?}, index {idx}"
1604
- ) ) ,
1605
- } ;
1606
- let result_pointee_size = self . lookup_type ( result_pointee_type) . sizeof ( self ) ;
1607
- let result_type = self . type_ptr_to ( result_pointee_type) ;
1608
-
1609
- // Special-case field accesses through a `pointercast`, to accesss the
1610
- // right field in the original type, for the `Logical` addressing model.
1611
- let ptr = ptr. strip_ptrcasts ( ) ;
1612
- let original_pointee_ty = match self . lookup_type ( ptr. ty ) {
1613
- SpirvType :: Pointer { pointee } => pointee,
1614
- other => self . fatal ( format ! ( "struct_gep called on non-pointer type: {other:?}" ) ) ,
1615
- } ;
1616
- if let Some ( ( indices, _) ) = self . recover_access_chain_from_offset (
1617
- original_pointee_ty,
1618
- offset,
1619
- result_pointee_size..=result_pointee_size,
1620
- Some ( result_pointee_type) ,
1621
- ) {
1622
- let original_ptr = ptr. def ( self ) ;
1623
- let indices = indices
1624
- . into_iter ( )
1625
- . map ( |idx| self . constant_u32 ( self . span ( ) , idx) . def ( self ) )
1626
- . collect :: < Vec < _ > > ( ) ;
1627
- return self
1628
- . emit ( )
1629
- . in_bounds_access_chain ( result_type, None , original_ptr, indices)
1630
- . unwrap ( )
1631
- . with_type ( result_type) ;
1632
- }
1633
-
1634
- // FIXME(eddyb) can we even get to this point, with valid SPIR-V?
1635
-
1636
- // HACK(eddyb) temporary workaround for untyped pointers upstream.
1637
- // FIXME(eddyb) replace with untyped memory SPIR-V + `qptr` or similar.
1638
- let ptr = self . pointercast ( ptr, self . type_ptr_to ( ty) ) ;
1639
-
1640
- // Important! LLVM, and therefore intel-compute-runtime, require the `getelementptr` instruction (and therefore
1641
- // OpAccessChain) on structs to be a constant i32. Not i64! i32.
1642
- if idx > u32:: MAX as u64 {
1643
- self . fatal ( "struct_gep bigger than u32::MAX" ) ;
1644
- }
1645
- let index_const = self . constant_u32 ( self . span ( ) , idx as u32 ) . def ( self ) ;
1646
- self . emit ( )
1647
- . in_bounds_access_chain (
1648
- result_type,
1649
- None ,
1650
- ptr. def ( self ) ,
1651
- [ index_const] . iter ( ) . cloned ( ) ,
1652
- )
1653
- . unwrap ( )
1654
- . with_type ( result_type)
1655
- }
1656
-
1657
1587
// intcast has the logic for dealing with bools, so use that
1658
1588
fn trunc ( & mut self , val : Self :: Value , dest_ty : Self :: Type ) -> Self :: Value {
1659
1589
self . intcast ( val, dest_ty, false )
0 commit comments