diff options
author | Hans Wennborg <hans@hanshq.net> | 2013-04-16 08:35:36 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2013-04-16 08:35:36 +0000 |
commit | c9e1d992796ba1dd20004495038fbf18deeadb65 (patch) | |
tree | 20f7e7768048cd93556bb0e5449909c20e450057 /llvm/lib/Transforms | |
parent | 8edce4ee6276df36969283bf98b8bef898fb548c (diff) | |
download | bcm5719-llvm-c9e1d992796ba1dd20004495038fbf18deeadb65.tar.gz bcm5719-llvm-c9e1d992796ba1dd20004495038fbf18deeadb65.zip |
simplifycfg: Fix integer overflow converting switch into icmp.
If a switch instruction has a case for every possible value of its type,
with the same successor, SimplifyCFG would replace it with an icmp ult,
but the computation of the bound overflows in that case, which inverts
the test.
Patch by Jed Davis!
llvm-svn: 179587
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 681bf9c2b7a..6de602e4c3e 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -3073,7 +3073,12 @@ static bool TurnSwitchRangeIntoICmp(SwitchInst *SI, IRBuilder<> &Builder) { Value *Sub = SI->getCondition(); if (!Offset->isNullValue()) Sub = Builder.CreateAdd(Sub, Offset, Sub->getName()+".off"); - Value *Cmp = Builder.CreateICmpULT(Sub, NumCases, "switch"); + Value *Cmp; + // If NumCases overflowed, then all possible values jump to the successor. + if (NumCases->isNullValue() && SI->getNumCases() != 0) + Cmp = ConstantInt::getTrue(SI->getContext()); + else + Cmp = Builder.CreateICmpULT(Sub, NumCases, "switch"); BranchInst *NewBI = Builder.CreateCondBr( Cmp, SI->case_begin().getCaseSuccessor(), SI->getDefaultDest()); |