@@ -192,34 +192,32 @@ 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 ;
197195 unsigned quotient = 0 , promoteToInt = 0 ;
198- promoteInt (srcWidth * numElements , quotient, promoteToInt, DL->getLargestLegalIntTypeSizeInBits ());
196+ promoteInt (srcWidth, quotient, promoteToInt, DL->getLargestLegalIntTypeSizeInBits ());
199197
200198 PHINode *oldPhi = cast<PHINode>(&I);
201199 Value *result = nullptr ;
202200
203201 if (quotient > 1 ) {
204- Type *newVecType = IGCLLVM::FixedVectorType::get (Type::getIntNTy (I.getContext (), promoteToInt), quotient);
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);
205206 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 *newOrigValue = m_builder->CreateBitCast (incomingValue, newOrigIntType);
214- Value *newLargeIntValue = m_builder->CreateZExt (newOrigValue, newLargeIntType);
213+ Value *newLargeIntValue = m_builder->CreateZExt (incomingValue, newLargeIntType);
215214 Value *newVecValue = m_builder->CreateBitCast (newLargeIntValue, newVecType);
216215 newPhi->addIncoming (newVecValue, oldPhi->getIncomingBlock (i));
217216 }
218217 // Cast back to original type
219218 m_builder->SetInsertPoint (newPhi->getParent ()->getFirstNonPHI ());
220219 Value *NewLargeIntPhi = m_builder->CreateBitCast (newPhi, newLargeIntType);
221- Value *NewOrigIntPhi = m_builder->CreateTrunc (NewLargeIntPhi, newOrigIntType);
222- result = m_builder->CreateBitCast (NewOrigIntPhi, oldPhi->getType ());
220+ result = m_builder->CreateTrunc (NewLargeIntPhi, oldPhi->getType ());
223221 } else {
224222 // quotient == 1 (integer promotion)
225223 Type *newType = Type::getIntNTy (I.getContext (), promoteToInt);
0 commit comments