@@ -1036,17 +1036,20 @@ static bool getInterchangeableInstruction(
1036
1036
1037
1037
static bool isConvertible(Instruction *I, Instruction *MainOp,
1038
1038
Instruction *AltOp) {
1039
- if (!I->isBinaryOp())
1040
- return I->getOpcode() == MainOp->getOpcode() ||
1041
- I->getOpcode() == AltOp->getOpcode();
1042
1039
assert(MainOp && "MainOp cannot be nullptr.");
1040
+ if (I->getOpcode() == MainOp->getOpcode())
1041
+ return true;
1042
+ assert(AltOp && "AltOp cannot be nullptr.");
1043
+ if (I->getOpcode() == AltOp->getOpcode())
1044
+ return true;
1045
+ if (!I->isBinaryOp())
1046
+ return false;
1043
1047
SmallVector<std::unique_ptr<InterchangeableInstruction>> Candidate(
1044
1048
getInterchangeableInstruction(I));
1045
1049
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)
1046
1050
if (C->isSame(I) && C->isSame(MainOp))
1047
1051
return true;
1048
1052
Candidate = getInterchangeableInstruction(I);
1049
- assert(AltOp && "AltOp cannot be nullptr.");
1050
1053
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)
1051
1054
if (C->isSame(I) && C->isSame(AltOp))
1052
1055
return true;
@@ -1056,10 +1059,12 @@ static bool isConvertible(Instruction *I, Instruction *MainOp,
1056
1059
static std::pair<Instruction *, SmallVector<Value *>>
1057
1060
convertTo(Instruction *I, Instruction *MainOp, Instruction *AltOp) {
1058
1061
assert(isConvertible(I, MainOp, AltOp) && "Cannot convert the instruction.");
1059
- if (!I->isBinaryOp())
1060
- return std::make_pair(I->getOpcode() == MainOp->getOpcode() ? MainOp
1061
- : AltOp,
1062
- SmallVector<Value *>(I->operands()));
1062
+ if (I->getOpcode() == MainOp->getOpcode())
1063
+ return std::make_pair(MainOp, SmallVector<Value *>(I->operands()));
1064
+ // Prefer AltOp instead of interchangeable instruction of MainOp.
1065
+ if (I->getOpcode() == AltOp->getOpcode())
1066
+ return std::make_pair(AltOp, SmallVector<Value *>(I->operands()));
1067
+ assert(I->isBinaryOp() && "Cannot convert the instruction.");
1063
1068
SmallVector<std::unique_ptr<InterchangeableInstruction>> Candidate(
1064
1069
getInterchangeableInstruction(I));
1065
1070
for (std::unique_ptr<InterchangeableInstruction> &C : Candidate)
0 commit comments