[llvm] r289439 - [InstCombine] clean up range-for-loops in visitSwitchInst(); NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 07:52:56 PST 2016
Author: spatel
Date: Mon Dec 12 09:52:56 2016
New Revision: 289439
URL: http://llvm.org/viewvc/llvm-project?rev=289439&view=rev
Log:
[InstCombine] clean up range-for-loops in visitSwitchInst(); NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=289439&r1=289438&r2=289439&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Mon Dec 12 09:52:56 2016
@@ -2260,18 +2260,18 @@ Instruction *InstCombiner::visitSwitchIn
Value *NewCond = Builder->CreateTrunc(Cond, Ty, "trunc");
SI.setCondition(NewCond);
- for (auto &C : SI.cases())
- static_cast<SwitchInst::CaseIt *>(&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::visitSwitchIn
Constant *NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
assert(isa<ConstantInt>(NewCaseVal) &&
"Result of expression should be constant");
- i.setValue(cast<ConstantInt>(NewCaseVal));
+ CaseIter.setValue(cast<ConstantInt>(NewCaseVal));
}
SI.setCondition(Op0);
if (auto *CondI = dyn_cast<Instruction>(Cond))
More information about the llvm-commits
mailing list