diff options
author | Sanjay Patel <spatel@rotateright.com> | 2016-05-20 14:53:09 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2016-05-20 14:53:09 +0000 |
commit | 75892a1543f6a5f2b6180b698b3d99c35681d305 (patch) | |
tree | bd0b6b37d1fa494897d3697f4a5c4f39d2be9bd2 /llvm/lib/Transforms | |
parent | ce6f3bdee4bb280aefb13263257f5b9b8d92f183 (diff) | |
download | bcm5719-llvm-75892a1543f6a5f2b6180b698b3d99c35681d305.tar.gz bcm5719-llvm-75892a1543f6a5f2b6180b698b3d99c35681d305.zip |
[SimplifyCFG] eliminate switch cases based on known range of switch condition
This was noted in PR24766:
https://llvm.org/bugs/show_bug.cgi?id=24766#c2
We may not know whether the sign bit(s) are zero or one, but we can still
optimize based on knowing that the sign bit is repeated.
Differential Revision: http://reviews.llvm.org/D20275
llvm-svn: 270222
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 16e886569e5..fb6a13fadc5 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3914,14 +3914,20 @@ static bool EliminateDeadSwitchCases(SwitchInst *SI, AssumptionCache *AC, APInt KnownZero(Bits, 0), KnownOne(Bits, 0); computeKnownBits(Cond, KnownZero, KnownOne, DL, 0, AC, SI); + // We can also eliminate cases by determining that their values are outside of + // the limited range of the condition based on how many significant (non-sign) + // bits are in the condition value. + unsigned ExtraSignBits = ComputeNumSignBits(Cond, DL, 0, AC, SI) - 1; + unsigned MaxSignificantBitsInCond = Bits - ExtraSignBits; + // Gather dead cases. SmallVector<ConstantInt *, 8> DeadCases; for (auto &Case : SI->cases()) { - if ((Case.getCaseValue()->getValue() & KnownZero) != 0 || - (Case.getCaseValue()->getValue() & KnownOne) != KnownOne) { + APInt CaseVal = Case.getCaseValue()->getValue(); + if ((CaseVal & KnownZero) != 0 || (CaseVal & KnownOne) != KnownOne || + (CaseVal.getMinSignedBits() > MaxSignificantBitsInCond)) { DeadCases.push_back(Case.getCaseValue()); - DEBUG(dbgs() << "SimplifyCFG: switch case '" << Case.getCaseValue() - << "' is dead.\n"); + DEBUG(dbgs() << "SimplifyCFG: switch case " << CaseVal << " is dead.\n"); } } |