Skip to content

Commit d0bdc33

Browse files
committed
IC/Select: refactor; address review
1 parent e575142 commit d0bdc33

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -423,11 +423,18 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
423423
}
424424
}
425425

426-
auto CreateCmpSel = [&](CmpPredicate P, Value *MatchOp) {
426+
auto CreateCmpSel = [&](std::optional<CmpPredicate> P,
427+
bool Swapped) -> CmpInst * {
428+
if (!P)
429+
return nullptr;
430+
auto *MatchOp = getCommonOp(TI, FI, ICmpInst::isEquality(*P),
431+
ICmpInst::isRelational(*P) && Swapped);
432+
if (!MatchOp)
433+
return nullptr;
427434
Value *NewSel = Builder.CreateSelect(Cond, OtherOpT, OtherOpF,
428435
SI.getName() + ".v", &SI);
429-
return new ICmpInst(MatchIsOpZero ? P
430-
: ICmpInst::getSwappedCmpPredicate(P),
436+
return new ICmpInst(MatchIsOpZero ? *P
437+
: ICmpInst::getSwappedCmpPredicate(*P),
431438
MatchOp, NewSel);
432439
};
433440

@@ -436,16 +443,14 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
436443
CmpPredicate TPred, FPred;
437444
if (match(TI, m_ICmp(TPred, m_Value(), m_Value())) &&
438445
match(FI, m_ICmp(FPred, m_Value(), m_Value()))) {
439-
if (auto P = CmpPredicate::getMatching(TPred, FPred)) {
440-
if (Value *MatchOp =
441-
getCommonOp(TI, FI, ICmpInst::isEquality(*P), false))
442-
return CreateCmpSel(*P, MatchOp);
443-
} else if (auto P = CmpPredicate::getMatching(
444-
TPred, ICmpInst::getSwappedCmpPredicate(FPred))) {
445-
if (Value *MatchOp =
446-
getCommonOp(TI, FI, ICmpInst::isEquality(*P), true))
447-
return CreateCmpSel(*P, MatchOp);
448-
}
446+
if (auto *R =
447+
CreateCmpSel(CmpPredicate::getMatching(TPred, FPred), false))
448+
return R;
449+
if (auto *R =
450+
CreateCmpSel(CmpPredicate::getMatching(
451+
TPred, ICmpInst::getSwappedCmpPredicate(FPred)),
452+
true))
453+
return R;
449454
}
450455
}
451456

0 commit comments

Comments
 (0)