@@ -926,9 +926,9 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
926
926
bool IsCmpOp = isa<CmpInst>(MainOp);
927
927
CmpInst::Predicate BasePred = IsCmpOp ? cast<CmpInst>(MainOp)->getPredicate()
928
928
: CmpInst::BAD_ICMP_PREDICATE;
929
+ Instruction *AltOp = MainOp;
929
930
unsigned Opcode = MainOp->getOpcode();
930
931
unsigned AltOpcode = Opcode;
931
- unsigned AltIndex = std::distance(VL.begin(), It);
932
932
933
933
bool SwappedPredsCompatible = IsCmpOp && [&]() {
934
934
SetVector<unsigned> UniquePreds, UniqueNonSwappedPreds;
@@ -979,7 +979,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
979
979
if (Opcode == AltOpcode && isValidForAlternation(InstOpcode) &&
980
980
isValidForAlternation(Opcode)) {
981
981
AltOpcode = InstOpcode;
982
- AltIndex = Cnt ;
982
+ AltOp = I ;
983
983
continue;
984
984
}
985
985
} else if (IsCastOp && isa<CastInst>(I)) {
@@ -995,7 +995,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
995
995
isValidForAlternation(InstOpcode) &&
996
996
"Cast isn't safe for alternation, logic needs to be updated!");
997
997
AltOpcode = InstOpcode;
998
- AltIndex = Cnt ;
998
+ AltOp = I ;
999
999
continue;
1000
1000
}
1001
1001
}
@@ -1020,18 +1020,17 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
1020
1020
1021
1021
if (isCmpSameOrSwapped(BaseInst, Inst, TLI))
1022
1022
continue;
1023
- auto *AltInst = cast<CmpInst>(VL[AltIndex]);
1024
- if (AltIndex) {
1025
- if (isCmpSameOrSwapped(AltInst, Inst, TLI))
1023
+ if (MainOp != AltOp) {
1024
+ if (isCmpSameOrSwapped(cast<CmpInst>(AltOp), Inst, TLI))
1026
1025
continue;
1027
1026
} else if (BasePred != CurrentPred) {
1028
1027
assert(
1029
1028
isValidForAlternation(InstOpcode) &&
1030
1029
"CmpInst isn't safe for alternation, logic needs to be updated!");
1031
- AltIndex = Cnt ;
1030
+ AltOp = I ;
1032
1031
continue;
1033
1032
}
1034
- CmpInst::Predicate AltPred = AltInst ->getPredicate();
1033
+ CmpInst::Predicate AltPred = cast<CmpInst>(AltOp) ->getPredicate();
1035
1034
if (BasePred == CurrentPred || BasePred == SwappedCurrentPred ||
1036
1035
AltPred == CurrentPred || AltPred == SwappedCurrentPred)
1037
1036
continue;
@@ -1082,7 +1081,7 @@ static InstructionsState getSameOpcode(ArrayRef<Value *> VL,
1082
1081
return InstructionsState::invalid();
1083
1082
}
1084
1083
1085
- return InstructionsState(MainOp, cast<Instruction>(VL[AltIndex] ));
1084
+ return InstructionsState(MainOp, cast<Instruction>(AltOp ));
1086
1085
}
1087
1086
1088
1087
/// \returns true if all of the values in \p VL have the same type or false
0 commit comments