@@ -3577,7 +3577,8 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) {
3577
3577
// is false/true.
3578
3578
static Value *simplifySwitchOnSelectUsingRanges (SwitchInst &SI,
3579
3579
SelectInst *Select,
3580
- unsigned CstOpIdx) {
3580
+ bool IsTrueArm) {
3581
+ unsigned CstOpIdx = IsTrueArm ? 1 : 2 ;
3581
3582
auto *C = dyn_cast<ConstantInt>(Select->getOperand (CstOpIdx));
3582
3583
if (!C)
3583
3584
return nullptr ;
@@ -3591,7 +3592,7 @@ static Value *simplifySwitchOnSelectUsingRanges(SwitchInst &SI,
3591
3592
if (!match (Select->getCondition (),
3592
3593
m_ICmp (Pred, m_Specific (X), m_APInt (RHSC))))
3593
3594
return nullptr ;
3594
- if (CstOpIdx == 1 )
3595
+ if (IsTrueArm )
3595
3596
Pred = ICmpInst::getInversePredicate (Pred);
3596
3597
3597
3598
// See whether we can replace the select with X
@@ -3679,10 +3680,10 @@ Instruction *InstCombinerImpl::visitSwitchInst(SwitchInst &SI) {
3679
3680
// Fold switch(select cond, X, Y) into switch(X/Y) if possible
3680
3681
if (auto *Select = dyn_cast<SelectInst>(Cond)) {
3681
3682
if (Value *V =
3682
- simplifySwitchOnSelectUsingRanges (SI, Select, /* CstOpIdx =*/ 1 ))
3683
+ simplifySwitchOnSelectUsingRanges (SI, Select, /* IsTrueArm =*/ true ))
3683
3684
return replaceOperand (SI, 0 , V);
3684
3685
if (Value *V =
3685
- simplifySwitchOnSelectUsingRanges (SI, Select, /* CstOpIdx =*/ 2 ))
3686
+ simplifySwitchOnSelectUsingRanges (SI, Select, /* IsTrueArm =*/ false ))
3686
3687
return replaceOperand (SI, 0 , V);
3687
3688
}
3688
3689
0 commit comments