Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: src/IceSwitchLowering.cpp

Issue 1247833003: Handle UINT64_MAX edge case in switch lowering. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Make test more readable. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==// 1 //===- subzero/src/IceSwitchLowering.cpp - Switch lowering -----------------==//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (NumCases * 2 <= TotalRange) 68 if (NumCases * 2 <= TotalRange)
69 return CaseClusters; 69 return CaseClusters;
70 // Unlikely. Would mean can't store size of jump table. 70 // Unlikely. Would mean can't store size of jump table.
71 if (TotalRange == UINT64_MAX) 71 if (TotalRange == UINT64_MAX)
72 return CaseClusters; 72 return CaseClusters;
73 ++TotalRange; 73 ++TotalRange;
74 74
75 // Replace everything with a jump table 75 // Replace everything with a jump table
76 InstJumpTable *JumpTable = 76 InstJumpTable *JumpTable =
77 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault()); 77 InstJumpTable::create(Func, TotalRange, Inst->getLabelDefault());
78 for (const CaseCluster &Case : CaseClusters) 78 for (const CaseCluster &Case : CaseClusters) {
79 for (uint64_t I = Case.Low; I <= Case.High; ++I) 79 // Case.High could be UINT64_MAX which makes the loop awkward. Unwrap the
80 // last iteration to avoid wrap around problems.
81 for (uint64_t I = Case.Low; I < Case.High; ++I)
80 JumpTable->addTarget(I - MinValue, Case.Label); 82 JumpTable->addTarget(I - MinValue, Case.Label);
83 JumpTable->addTarget(Case.High - MinValue, Case.Label);
84 }
81 85
82 CaseClusters.clear(); 86 CaseClusters.clear();
83 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable); 87 CaseClusters.emplace_back(MinValue, MaxValue, JumpTable);
84 88
85 return CaseClusters; 89 return CaseClusters;
86 } 90 }
87 91
88 bool CaseCluster::tryAppend(const CaseCluster &New) { 92 bool CaseCluster::tryAppend(const CaseCluster &New) {
89 // Can only append ranges with the same target and are adjacent 93 // Can only append ranges with the same target and are adjacent
90 bool CanAppend = this->Label == New.Label && this->High + 1 == New.Low; 94 bool CanAppend = this->Label == New.Label && this->High + 1 == New.Low;
91 if (CanAppend) 95 if (CanAppend)
92 this->High = New.High; 96 this->High = New.High;
93 return CanAppend; 97 return CanAppend;
94 } 98 }
95 99
96 } // end of namespace Ice 100 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | tests_lit/llvm2ice_tests/adv-switch-opt.ll » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698