@@ -527,13 +527,15 @@ legalizeGetHighLowi64Bytes(Instruction &I,
527527 }
528528
529529 if (auto *Extract = dyn_cast<ExtractElementInst>(&I)) {
530+ if (!dyn_cast<BitCastInst>(Extract->getVectorOperand ()))
531+ return ;
530532 auto *VecTy = dyn_cast<FixedVectorType>(Extract->getVectorOperandType ());
531533 if (VecTy && VecTy->getElementType ()->isIntegerTy (32 ) &&
532534 VecTy->getNumElements () == 2 ) {
533535 if (auto *Index = dyn_cast<ConstantInt>(Extract->getIndexOperand ())) {
534536 unsigned Idx = Index->getZExtValue ();
535537 IRBuilder<> Builder (&I);
536- assert (dyn_cast<BitCastInst>(Extract-> getVectorOperand ()));
538+
537539 auto *Replacement = ReplacedValues[Extract->getVectorOperand ()];
538540 assert (Replacement && " The BitCast replacement should have been set "
539541 " before working on ExtractElementInst." );
@@ -600,6 +602,11 @@ class DXILLegalizationPipeline {
600602 LegalizationPipeline[Stage1].push_back (legalizeMemCpy);
601603 LegalizationPipeline[Stage1].push_back (removeMemSet);
602604 LegalizationPipeline[Stage1].push_back (updateFnegToFsub);
605+ // Note: legalizeGetHighLowi64Bytes and
606+ // downcastI64toI32InsertExtractElements both modify extractelement, so they
607+ // must run staggered stages. legalizeGetHighLowi64Bytes runs first b\c it
608+ // removes extractelements, reducing the number that
609+ // downcastI64toI32InsertExtractElements needs to handle.
603610 LegalizationPipeline[Stage2].push_back (
604611 downcastI64toI32InsertExtractElements);
605612 }
0 commit comments