summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-09-20 22:31:35 +0000
committerSanjay Patel <spatel@rotateright.com>2017-09-20 22:31:35 +0000
commit73811a152a24a8ed6fbc0ec608ec04bc95db4c7d (patch)
treed13f4fe3816ecaf35ac0ae6183609d972ea700d0 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parentbb8636477d1cc52ad777dfa3cc9548832eb42003 (diff)
downloadbcm5719-llvm-73811a152a24a8ed6fbc0ec608ec04bc95db4c7d.tar.gz
bcm5719-llvm-73811a152a24a8ed6fbc0ec608ec04bc95db4c7d.zip
[SimplifyCFG] don't create a no-op subtract
I noticed this inefficiency while investigating PR34603: https://bugs.llvm.org/show_bug.cgi?id=34603 This fix will likely push another bug (we don't maintain state of 'LateSimplifyCFG') into hiding, but I'll try to clean that up with a follow-up patch anyway. llvm-svn: 313829
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 52e07e049a0..290f4151c0a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5275,8 +5275,12 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
// Compute the table index value.
Builder.SetInsertPoint(SI);
- Value *TableIndex =
- Builder.CreateSub(SI->getCondition(), MinCaseVal, "switch.tableidx");
+ Value *TableIndex;
+ if (MinCaseVal->isNullValue())
+ TableIndex = SI->getCondition();
+ else
+ TableIndex = Builder.CreateSub(SI->getCondition(), MinCaseVal,
+ "switch.tableidx");
// Compute the maximum table size representable by the integer type we are
// switching upon.
OpenPOWER on IntegriCloud