Skip to content

Commit 1828c72

Browse files
committed
[InstCombine] Address comments.
1 parent 28ed09c commit 1828c72

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3577,7 +3577,8 @@ Instruction *InstCombinerImpl::visitBranchInst(BranchInst &BI) {
35773577
// is false/true.
35783578
static Value *simplifySwitchOnSelectUsingRanges(SwitchInst &SI,
35793579
SelectInst *Select,
3580-
unsigned CstOpIdx) {
3580+
bool IsTrueArm) {
3581+
unsigned CstOpIdx = IsTrueArm ? 1 : 2;
35813582
auto *C = dyn_cast<ConstantInt>(Select->getOperand(CstOpIdx));
35823583
if (!C)
35833584
return nullptr;
@@ -3591,7 +3592,7 @@ static Value *simplifySwitchOnSelectUsingRanges(SwitchInst &SI,
35913592
if (!match(Select->getCondition(),
35923593
m_ICmp(Pred, m_Specific(X), m_APInt(RHSC))))
35933594
return nullptr;
3594-
if (CstOpIdx == 1)
3595+
if (IsTrueArm)
35953596
Pred = ICmpInst::getInversePredicate(Pred);
35963597

35973598
// See whether we can replace the select with X
@@ -3679,10 +3680,10 @@ Instruction *InstCombinerImpl::visitSwitchInst(SwitchInst &SI) {
36793680
// Fold switch(select cond, X, Y) into switch(X/Y) if possible
36803681
if (auto *Select = dyn_cast<SelectInst>(Cond)) {
36813682
if (Value *V =
3682-
simplifySwitchOnSelectUsingRanges(SI, Select, /*CstOpIdx=*/1))
3683+
simplifySwitchOnSelectUsingRanges(SI, Select, /*IsTrueArm=*/true))
36833684
return replaceOperand(SI, 0, V);
36843685
if (Value *V =
3685-
simplifySwitchOnSelectUsingRanges(SI, Select, /*CstOpIdx=*/2))
3686+
simplifySwitchOnSelectUsingRanges(SI, Select, /*IsTrueArm=*/false))
36863687
return replaceOperand(SI, 0, V);
36873688
}
36883689

0 commit comments

Comments
 (0)