[llvm-branch-commits] [llvm-branch] r115823 - /llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp
Gabor Greif
ggreif at gmail.com
Wed Oct 6 13:06:42 PDT 2010
Author: ggreif
Date: Wed Oct 6 15:06:42 2010
New Revision: 115823
URL: http://llvm.org/viewvc/llvm-project?rev=115823&view=rev
Log:
simplify by moving out some functionality into ChopOffSwitchLeg
Modified:
llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp
Modified: llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=115823&r1=115822&r2=115823&view=diff
==============================================================================
--- llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/branches/ggreif/switch-opts/lib/Transforms/Scalar/CodeGenPrepare.cpp Wed Oct 6 15:06:42 2010
@@ -875,6 +875,18 @@
return MadeChange;
}
+BasicBlock *ChopOffSwitchLeg(SwitchInst *I, Value *OrigCondition, ConstantInt *Val,
+ BasicBlock *Old, const char *CmpName) {
+ if (unsigned Leg = I->findCaseValue(Val)) {
+ BasicBlock *New = Old->splitBasicBlock(I, Old->getName()+".switch");
+ Old->getTerminator()->eraseFromParent();
+ Instruction *Cmp = new ICmpInst(*Old, CmpInst::ICMP_EQ, OrigCondition, Val, CmpName);
+ BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
+ I->removeCase(Leg);
+ return New;
+ }
+ return 0;
+}
static bool OptimizeSwitchInst(SwitchInst *I, Value *OrigCondition) {
BasicBlock *Old = I->getParent();
@@ -895,7 +907,7 @@
if (TruncInst *T = dyn_cast<TruncInst>(condition)) {
if (Instruction *P = dyn_cast<Instruction>(T->getOperand(0))) {
if (Old != P->getParent() ||
- condition != next(BasicBlock::iterator(P))/* TODO: CHEAP TRUNCATES*/)
+ condition != next(BasicBlock::iterator(P))/* TODO: TLI->CHEAP TRUNCATES*/)
return false;
condition = P;
}
@@ -906,12 +918,14 @@
if (BinaryOperator *A = dyn_cast<BinaryOperator>(condition)) {
if (A->getOpcode() == Instruction::And) {
ConstantInt *Zero(cast<ConstantInt>(ConstantInt::get(Ty, 0)));
+ if (BasicBlock *New = ChopOffSwitchLeg(I, OrigCondition, Zero, Old, "tst")) {
+ /*
if (unsigned Leg = I->findCaseValue(Zero)) {
BasicBlock *New = Old->splitBasicBlock(I, Old->getName()+".switch");
Old->getTerminator()->eraseFromParent();
Instruction *Cmp = new ICmpInst(*Old, CmpInst::ICMP_EQ, OrigCondition, Zero, "tst");
BranchInst::Create(I->getSuccessor(Leg), New, Cmp, Old);
- I->removeCase(Leg);
+ I->removeCase(Leg);*/
APInt Mask(cast<IntegerType>(Ty)->getMask());
APInt KnownZero(Mask.getBitWidth(), 0), KnownOne(Mask.getBitWidth(), 0);
@@ -924,13 +938,17 @@
APInt Middle(KnownZeroInverted | KnownOne);
Middle.clear(KnownZeroInverted.countTrailingZeros());
ConstantInt *Mid(cast<ConstantInt>(ConstantInt::get(Ty, Middle)));
+
+ if (BasicBlock *New2 = ChopOffSwitchLeg(I, OrigCondition, Mid, New, "mid?")) {
+ }
+ /*
if (unsigned MidLeg = I->findCaseValue(Mid)) {
BasicBlock *New2 = New->splitBasicBlock(I, New->getName()+".switch2");
New->getTerminator()->eraseFromParent();
Instruction *MidCmp = new ICmpInst(*New, CmpInst::ICMP_EQ, OrigCondition, Mid, "mid?");
BranchInst::Create(I->getSuccessor(MidLeg), New2, MidCmp, New);
I->removeCase(MidLeg);
- }
+ }*/
return true;
}
}
More information about the llvm-branch-commits
mailing list