diff options
author | Chris Lattner <sabre@nondot.org> | 2004-07-03 00:26:11 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-07-03 00:26:11 +0000 |
commit | 4c9c20af282adbd2abfd7328f74986460761cf35 (patch) | |
tree | 72bbb7f10392d948a37b14e5f57aeeb60aac8466 /llvm/lib | |
parent | 3a03c90085307702317a0de1282d58db81dc8323 (diff) | |
download | bcm5719-llvm-4c9c20af282adbd2abfd7328f74986460761cf35.tar.gz bcm5719-llvm-4c9c20af282adbd2abfd7328f74986460761cf35.zip |
Implement add.ll:test22, a common case in MSIL files
llvm-svn: 14587
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index bf571194864..c0d0591c9b3 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -122,6 +122,7 @@ namespace { Instruction *visitFreeInst(FreeInst &FI); Instruction *visitLoadInst(LoadInst &LI); Instruction *visitBranchInst(BranchInst &BI); + Instruction *visitSwitchInst(SwitchInst &SI); // visitInstruction - Specify what to return for unhandled instructions... Instruction *visitInstruction(Instruction &I) { return 0; } @@ -3004,6 +3005,23 @@ Instruction *InstCombiner::visitBranchInst(BranchInst &BI) { return 0; } +Instruction *InstCombiner::visitSwitchInst(SwitchInst &SI) { + Value *Cond = SI.getCondition(); + 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' + for (unsigned i = 2, e = SI.getNumOperands(); i != e; i += 2) + SI.setOperand(i, ConstantExpr::getSub(cast<Constant>(SI.getOperand(i)), + AddRHS)); + SI.setOperand(0, I->getOperand(0)); + WorkList.push_back(I); + return &SI; + } + } + return 0; +} + void InstCombiner::removeFromWorkList(Instruction *I) { WorkList.erase(std::remove(WorkList.begin(), WorkList.end(), I), |