@@ -926,9 +926,9 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
926926 bool IsCmpOp = isa<CmpInst>(MainOp);
927927 CmpInst::Predicate BasePred = IsCmpOp ? cast<CmpInst>(MainOp)->getPredicate()
928928 : CmpInst::BAD_ICMP_PREDICATE;
929+ Instruction *AltOp = MainOp;
929930 unsigned Opcode = MainOp->getOpcode();
930931 unsigned AltOpcode = Opcode;
931- unsigned AltIndex = std::distance(VL.begin(), It);
932932
933933 bool SwappedPredsCompatible = IsCmpOp && [&]() {
934934 SetVector<unsigned> UniquePreds, UniqueNonSwappedPreds;
@@ -979,7 +979,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
979979 if (Opcode == AltOpcode && isValidForAlternation(InstOpcode) &&
980980 isValidForAlternation(Opcode)) {
981981 AltOpcode = InstOpcode;
982- AltIndex = Cnt ;
982+ AltOp = I ;
983983 continue;
984984 }
985985 } else if (IsCastOp && isa<CastInst>(I)) {
@@ -995,7 +995,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
995995 isValidForAlternation(InstOpcode) &&
996996 "Cast isn't safe for alternation, logic needs to be updated!");
997997 AltOpcode = InstOpcode;
998- AltIndex = Cnt ;
998+ AltOp = I ;
999999 continue;
10001000 }
10011001 }
@@ -1020,15 +1020,15 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
10201020
10211021 if (isCmpSameOrSwapped(BaseInst, Inst, TLI))
10221022 continue;
1023- auto *AltInst = cast<CmpInst>(VL[AltIndex] );
1024- if (AltIndex ) {
1023+ auto *AltInst = cast<CmpInst>(AltOp );
1024+ if (MainOp != AltOp ) {
10251025 if (isCmpSameOrSwapped(AltInst, Inst, TLI))
10261026 continue;
10271027 } else if (BasePred != CurrentPred) {
10281028 assert(
10291029 isValidForAlternation(InstOpcode) &&
10301030 "CmpInst isn't safe for alternation, logic needs to be updated!");
1031- AltIndex = Cnt ;
1031+ AltOp = I ;
10321032 continue;
10331033 }
10341034 CmpInst::Predicate AltPred = AltInst->getPredicate();
@@ -1082,7 +1082,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
10821082 return InstructionsState::invalid();
10831083 }
10841084
1085- return InstructionsState(MainOp, cast<Instruction>(VL[AltIndex]) );
1085+ return InstructionsState(MainOp, AltOp );
10861086}
10871087
10881088/// \returns true if all of the values in \p VL have the same type or false
0 commit comments