Skip to content

Commit e575142

Browse files
committed
IC/Select: refactor with lambda; address review
1 parent 3f0db8b commit e575142

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

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

426+
auto CreateCmpSel = [&](CmpPredicate P, Value *MatchOp) {
427+
Value *NewSel = Builder.CreateSelect(Cond, OtherOpT, OtherOpF,
428+
SI.getName() + ".v", &SI);
429+
return new ICmpInst(MatchIsOpZero ? P
430+
: ICmpInst::getSwappedCmpPredicate(P),
431+
MatchOp, NewSel);
432+
};
433+
426434
// icmp with a common operand also can have the common operand
427435
// pulled after the select.
428436
CmpPredicate TPred, FPred;
429437
if (match(TI, m_ICmp(TPred, m_Value(), m_Value())) &&
430438
match(FI, m_ICmp(FPred, m_Value(), m_Value()))) {
431-
auto P = CmpPredicate::getMatching(TPred, FPred);
432-
bool Swapped = !P;
433-
if (Swapped)
434-
P = CmpPredicate::getMatching(TPred,
435-
ICmpInst::getSwappedCmpPredicate(FPred));
436-
if (P) {
439+
if (auto P = CmpPredicate::getMatching(TPred, FPred)) {
437440
if (Value *MatchOp =
438-
getCommonOp(TI, FI, ICmpInst::isEquality(*P), Swapped)) {
439-
Value *NewSel = Builder.CreateSelect(Cond, OtherOpT, OtherOpF,
440-
SI.getName() + ".v", &SI);
441-
return new ICmpInst(
442-
MatchIsOpZero ? *P : ICmpInst::getSwappedCmpPredicate(*P),
443-
MatchOp, NewSel);
444-
}
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);
445448
}
446449
}
447450
}

0 commit comments

Comments
 (0)