@@ -423,11 +423,18 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
423
423
}
424
424
}
425
425
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 ;
427
434
Value *NewSel = Builder.CreateSelect (Cond, OtherOpT, OtherOpF,
428
435
SI.getName () + " .v" , &SI);
429
- return new ICmpInst (MatchIsOpZero ? P
430
- : ICmpInst::getSwappedCmpPredicate (P),
436
+ return new ICmpInst (MatchIsOpZero ? * P
437
+ : ICmpInst::getSwappedCmpPredicate (* P),
431
438
MatchOp, NewSel);
432
439
};
433
440
@@ -436,16 +443,14 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst &SI, Instruction *TI,
436
443
CmpPredicate TPred, FPred;
437
444
if (match (TI, m_ICmp (TPred, m_Value (), m_Value ())) &&
438
445
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;
449
454
}
450
455
}
451
456
0 commit comments