summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2016-05-13 21:51:17 +0000
committerSanjay Patel <spatel@rotateright.com>2016-05-13 21:51:17 +0000
commitabbc2ac2312dfe518459f38b3e95ff90aa60500d (patch)
treeb4dbf0b7e4b0579936162600773358fb77a69ec4 /llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
parentbe1b4e4dc6c03a9055e117082cd481dc74398d0e (diff)
downloadbcm5719-llvm-abbc2ac2312dfe518459f38b3e95ff90aa60500d.tar.gz
bcm5719-llvm-abbc2ac2312dfe518459f38b3e95ff90aa60500d.zip
use 'match' for less indenting; NFCI
llvm-svn: 269494
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstructionCombining.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp41
1 files changed, 20 insertions, 21 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index cc3d168677d..7a5964519a7 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -2213,28 +2213,27 @@ Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) {
SI.getContext(), C.getCaseValue()->getValue().trunc(NewWidth)));
}
- if (Instruction *I = dyn_cast<Instruction>(Cond)) {
- if (I->getOpcode() == Instruction::Add)
- if (ConstantInt *AddRHS = dyn_cast<ConstantInt>(I->getOperand(1))) {
- // change 'switch (X+4) case 1:' into 'switch (X) case -3'
- // Skip the first item since that's the default case.
- for (SwitchInst::CaseIt i = SI.case_begin(), e = SI.case_end();
- i != e; ++i) {
- ConstantInt* CaseVal = i.getCaseValue();
- Constant *LHS = CaseVal;
- if (TruncCond)
- LHS = LeadingKnownZeros
- ? ConstantExpr::getZExt(CaseVal, Cond->getType())
- : ConstantExpr::getSExt(CaseVal, Cond->getType());
- Constant* NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
- assert(isa<ConstantInt>(NewCaseVal) &&
- "Result of expression should be constant");
- i.setValue(cast<ConstantInt>(NewCaseVal));
- }
- SI.setCondition(I->getOperand(0));
- Worklist.Add(I);
- return &SI;
+ ConstantInt *AddRHS = nullptr;
+ if (match(Cond, m_Add(m_Value(), m_ConstantInt(AddRHS)))) {
+ Instruction *I = cast<Instruction>(Cond);
+ // 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();
+ Constant *LHS = CaseVal;
+ if (TruncCond) {
+ LHS = LeadingKnownZeros
+ ? ConstantExpr::getZExt(CaseVal, Cond->getType())
+ : ConstantExpr::getSExt(CaseVal, Cond->getType());
}
+ Constant *NewCaseVal = ConstantExpr::getSub(LHS, AddRHS);
+ assert(isa<ConstantInt>(NewCaseVal) &&
+ "Result of expression should be constant");
+ i.setValue(cast<ConstantInt>(NewCaseVal));
+ }
+ SI.setCondition(I->getOperand(0));
+ Worklist.Add(I);
+ return &SI;
}
return TruncCond ? &SI : nullptr;
OpenPOWER on IntegriCloud