@@ -423,25 +423,28 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
423
423
}
424
424
}
425
425
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
+
426
434
// icmp with a common operand also can have the common operand
427
435
// pulled after the select.
428
436
CmpPredicate TPred, FPred;
429
437
if (match (TI, m_ICmp (TPred, m_Value (), m_Value ())) &&
430
438
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)) {
437
440
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);
445
448
}
446
449
}
447
450
}
0 commit comments