From: Sanjay Patel Date: Mon, 12 Dec 2016 15:52:56 +0000 (+0000) Subject: [InstCombine] clean up range-for-loops in visitSwitchInst(); NFCI X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d616cee95a399389d9d815e997a5be950a9801fb;p=llvm [InstCombine] clean up range-for-loops in visitSwitchInst(); NFCI git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@289439 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp index 90eba686966..f96766db6df 100644 --- a/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -2260,18 +2260,18 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) { Value *NewCond = Builder->CreateTrunc(Cond, Ty, "trunc"); SI.setCondition(NewCond); - for (auto &C : SI.cases()) - static_cast(&C)->setValue(ConstantInt::get( - SI.getContext(), C.getCaseValue()->getValue().trunc(NewWidth))); + for (SwitchInst::CaseIt CaseIter : SI.cases()) { + APInt TruncatedCase = CaseIter.getCaseValue()->getValue().trunc(NewWidth); + CaseIter.setValue(ConstantInt::get(SI.getContext(), TruncatedCase)); + } } Value *Op0 = nullptr; ConstantInt *AddRHS = nullptr; if (match(Cond, m_Add(m_Value(Op0), m_ConstantInt(AddRHS)))) { // Change 'switch (X+4) case 1:' into 'switch (X) case -3'. - for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end(); i != e; - ++i) { - ConstantInt *CaseVal = i.getCaseValue(); + for (SwitchInst::CaseIt CaseIter : SI.cases()) { + ConstantInt *CaseVal = CaseIter.getCaseValue(); Constant *LHS = CaseVal; if (TruncCond) { LHS = LeadingKnownZeros @@ -2281,7 +2281,7 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) { Constant *NewCaseVal = ConstantExpr::getSub(LHS, AddRHS); assert(isa(NewCaseVal) && "Result of expression should be constant"); - i.setValue(cast(NewCaseVal)); + CaseIter.setValue(cast(NewCaseVal)); } SI.setCondition(Op0); if (auto *CondI = dyn_cast(Cond))