@@ -192,32 +192,34 @@ void PeepholeTypeLegalizer::legalizePhiInstruction(Instruction &I) {
192192 if (!I.getType ()->isIntOrIntVectorTy () || isLegalInteger (srcWidth) || srcWidth == 1 ) // nothing to legalize
193193 return ;
194194
195+ unsigned numElements =
196+ I.getType ()->isVectorTy () ? (unsigned )cast<IGCLLVM::FixedVectorType>(I.getType ())->getNumElements () : 1 ;
195197 unsigned quotient = 0 , promoteToInt = 0 ;
196- promoteInt (srcWidth, quotient, promoteToInt, DL->getLargestLegalIntTypeSizeInBits ());
198+ promoteInt (srcWidth * numElements , quotient, promoteToInt, DL->getLargestLegalIntTypeSizeInBits ());
197199
198200 PHINode *oldPhi = cast<PHINode>(&I);
199201 Value *result = nullptr ;
200202
201203 if (quotient > 1 ) {
202- unsigned numElements =
203- I.getType ()->isVectorTy () ? (unsigned )cast<IGCLLVM::FixedVectorType>(I.getType ())->getNumElements () : 1 ;
204- Type *newVecType =
205- IGCLLVM::FixedVectorType::get (Type::getIntNTy (I.getContext (), promoteToInt), quotient * numElements);
204+ Type *newVecType = IGCLLVM::FixedVectorType::get (Type::getIntNTy (I.getContext (), promoteToInt), quotient);
206205 Type *newLargeIntType = Type::getIntNTy (I.getContext (), promoteToInt * quotient);
206+ Type *newOrigIntType = Type::getIntNTy (I.getContext (), srcWidth * numElements);
207207
208208 PHINode *newPhi = m_builder->CreatePHI (newVecType, oldPhi->getNumIncomingValues ());
209209 for (unsigned i = 0 ; i < oldPhi->getNumIncomingValues (); i++) {
210210 Value *incomingValue = oldPhi->getIncomingValue (i);
211211
212212 m_builder->SetInsertPoint (oldPhi->getIncomingBlock (i)->getTerminator ());
213- Value *newLargeIntValue = m_builder->CreateZExt (incomingValue, newLargeIntType);
213+ Value *newOrigValue = m_builder->CreateBitCast (incomingValue, newOrigIntType);
214+ Value *newLargeIntValue = m_builder->CreateZExt (newOrigValue, newLargeIntType);
214215 Value *newVecValue = m_builder->CreateBitCast (newLargeIntValue, newVecType);
215216 newPhi->addIncoming (newVecValue, oldPhi->getIncomingBlock (i));
216217 }
217218 // Cast back to original type
218219 m_builder->SetInsertPoint (newPhi->getParent ()->getFirstNonPHI ());
219220 Value *NewLargeIntPhi = m_builder->CreateBitCast (newPhi, newLargeIntType);
220- result = m_builder->CreateTrunc (NewLargeIntPhi, oldPhi->getType ());
221+ Value *NewOrigIntPhi = m_builder->CreateTrunc (NewLargeIntPhi, newOrigIntType);
222+ result = m_builder->CreateBitCast (NewOrigIntPhi, oldPhi->getType ());
221223 } else {
222224 // quotient == 1 (integer promotion)
223225 Type *newType = Type::getIntNTy (I.getContext (), promoteToInt);
0 commit comments