11/* ========================== begin_copyright_notice ============================
22
3- Copyright (C) 2021-2024 Intel Corporation
3+ Copyright (C) 2021-2025 Intel Corporation
44
55SPDX-License-Identifier: MIT
66
@@ -1582,6 +1582,16 @@ bool Substituter::processGEP(GetElementPtrInst &GEPI,
15821582 unsigned PlainTyIdx = FindIt - GottenTypeArr.begin ();
15831583
15841584 if (PlainTyIdx == Size) {
1585+ Type *PrevType = IdxPath.getTyAt (Size - 1 );
1586+ // In case of opaque pointers, GEP's leading zero indices can be omitted and
1587+ // in this case previous type is not a structure type
1588+ if (!isa<StructType>(PrevType)) {
1589+ Type *PlainType = getBaseTy (GottenTypeArr[Size - 1 ]);
1590+ Instruction *ToInsert =
1591+ generateNewGEPs (GEPI, *PlainType, IdxPath, NewInstr, Size - 1 );
1592+ InstToInst.emplace_back (cast<Instruction>(&GEPI), ToInsert);
1593+ return true ;
1594+ }
15851595 // Case of FE1
15861596 auto InstUses = getInstUses (GEPI);
15871597 if (!InstUses)
@@ -1590,7 +1600,6 @@ bool Substituter::processGEP(GetElementPtrInst &GEPI,
15901600
15911601 // That means that we are getting split struct so we need to create GEPs.
15921602 // STyToBeSplit is the result of the instruction.
1593- Type *PrevType = IdxPath.getTyAt (Size - 1 );
15941603 unsigned Idx = IdxPath.getIdxAt (Size - 1 );
15951604 StructType *STyToBeSplit = cast<StructType>(PrevType);
15961605 const ListOfSplitElements &ListOfPossibleTypes =
@@ -1621,14 +1630,18 @@ bool Substituter::processGEP(GetElementPtrInst &GEPI,
16211630 return false ;
16221631 } else {
16231632 Type *PrevType = IdxPath.getTyAt (PlainTyIdx);
1624- unsigned Idx = IdxPath.getIdxAt (PlainTyIdx);
1625- StructType *STyToBeSplit = cast<StructType>(PrevType);
1626- IGC_ASSERT_MESSAGE (
1627- Graph.getElementsListOfSTyAtIdx (*STyToBeSplit, Idx).size () == 1 ,
1628- " Access to element of Struct does not get unsplit type." );
16291633 Type *PlainType = getBaseTy (GottenTypeArr[PlainTyIdx]);
1634+ // In case of opaque pointers, GEP's leading zero indices can be omitted and
1635+ // in this case previous type is not a structure type
1636+ if (auto *STyToBeSplit = dyn_cast<StructType>(PrevType)) {
1637+ unsigned Idx = IdxPath.getIdxAt (PlainTyIdx);
1638+ IGC_ASSERT_MESSAGE (
1639+ Graph.getElementsListOfSTyAtIdx (*STyToBeSplit, Idx).size () == 1 ,
1640+ " Access to element of Struct does not get unsplit type." );
1641+ PlainTyIdx += 1 ;
1642+ }
16301643 Instruction *ToInsert =
1631- generateNewGEPs (GEPI, *PlainType, IdxPath, NewInstr, PlainTyIdx + 1 );
1644+ generateNewGEPs (GEPI, *PlainType, IdxPath, NewInstr, PlainTyIdx);
16321645 InstToInst.emplace_back (cast<Instruction>(&GEPI), ToInsert);
16331646 }
16341647 return true ;
0 commit comments