@@ -405,13 +405,15 @@ bool VectorCombine::isExtractExtractCheap(ExtractElementInst *Ext0,
405405 const Instruction &I,
406406 ExtractElementInst *&ConvertToShuffle,
407407 unsigned PreferredExtractIndex) {
408- auto *Ext0IndexC = dyn_cast<ConstantInt>(Ext0->getOperand ( 1 ));
409- auto *Ext1IndexC = dyn_cast<ConstantInt>(Ext1->getOperand ( 1 ));
408+ auto *Ext0IndexC = dyn_cast<ConstantInt>(Ext0->getIndexOperand ( ));
409+ auto *Ext1IndexC = dyn_cast<ConstantInt>(Ext1->getIndexOperand ( ));
410410 assert (Ext0IndexC && Ext1IndexC && " Expected constant extract indexes" );
411411
412412 unsigned Opcode = I.getOpcode ();
413+ Value *Ext0Src = Ext0->getVectorOperand ();
414+ Value *Ext1Src = Ext1->getVectorOperand ();
413415 Type *ScalarTy = Ext0->getType ();
414- auto *VecTy = cast<VectorType>(Ext0-> getOperand ( 0 ) ->getType ());
416+ auto *VecTy = cast<VectorType>(Ext0Src ->getType ());
415417 InstructionCost ScalarOpCost, VectorOpCost;
416418
417419 // Get cost estimates for scalar and vector versions of the operation.
@@ -452,7 +454,7 @@ bool VectorCombine::isExtractExtractCheap(ExtractElementInst *Ext0,
452454 // Extra uses of the extracts mean that we include those costs in the
453455 // vector total because those instructions will not be eliminated.
454456 InstructionCost OldCost, NewCost;
455- if (Ext0-> getOperand ( 0 ) == Ext1-> getOperand ( 0 ) && Ext0Index == Ext1Index) {
457+ if (Ext0Src == Ext1Src && Ext0Index == Ext1Index) {
456458 // Handle a special case. If the 2 extracts are identical, adjust the
457459 // formulas to account for that. The extra use charge allows for either the
458460 // CSE'd pattern or an unoptimized form with identical values:
@@ -513,12 +515,12 @@ static ExtractElementInst *translateExtract(ExtractElementInst *ExtElt,
513515 unsigned NewIndex,
514516 IRBuilder<> &Builder) {
515517 // Shufflevectors can only be created for fixed-width vectors.
516- if (!isa<FixedVectorType>(ExtElt->getOperand (0 )->getType ()))
518+ Value *X = ExtElt->getVectorOperand ();
519+ if (!isa<FixedVectorType>(X->getType ()))
517520 return nullptr ;
518521
519522 // If the extract can be constant-folded, this code is unsimplified. Defer
520523 // to other passes to handle that.
521- Value *X = ExtElt->getVectorOperand ();
522524 Value *C = ExtElt->getIndexOperand ();
523525 assert (isa<ConstantInt>(C) && " Expected a constant index operand" );
524526 if (isa<Constant>(X))
0 commit comments