diff options
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 7 | ||||
-rw-r--r-- | llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll | 6 |
2 files changed, 8 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index a8a97f0e25c..e3bdd6066be 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -4074,9 +4074,12 @@ static bool SwitchToLookupTable(SwitchInst *SI, CommonDest->getParent(), CommonDest); + // Make the mask's bitwidth at least 8bit and a power-of-2 to avoid + // unnecessary illegal types. + uint64_t TableSizePowOf2 = NextPowerOf2(std::max(7ULL, TableSize - 1ULL)); + APInt MaskInt(TableSizePowOf2, 0); + APInt One(TableSizePowOf2, 1); // Build bitmask; fill in a 1 bit for every case. - APInt MaskInt(TableSize, 0); - APInt One(TableSize, 1); const ResultListTy &ResultList = ResultLists[PHIs[0]]; for (size_t I = 0, E = ResultList.size(); I != E; ++I) { uint64_t Idx = (ResultList[I].first->getValue() - diff --git a/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll b/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll index b9f0e49cbe6..fc22e7eb455 100644 --- a/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll +++ b/llvm/test/Transforms/SimplifyCFG/X86/switch_to_lookup_table.ll @@ -856,10 +856,10 @@ return: ; CHECK: entry: ; CHECK: br i1 %{{.*}}, label %switch.hole_check, label %sw.default ; CHECK: switch.hole_check: -; CHECK-NEXT: %switch.maskindex = trunc i32 %switch.tableidx to i6 -; CHECK-NEXT: %switch.shifted = lshr i6 -17, %switch.maskindex +; CHECK-NEXT: %switch.maskindex = trunc i32 %switch.tableidx to i8 +; CHECK-NEXT: %switch.shifted = lshr i8 47, %switch.maskindex ; The mask is binary 101111. -; CHECK-NEXT: %switch.lobit = trunc i6 %switch.shifted to i1 +; CHECK-NEXT: %switch.lobit = trunc i8 %switch.shifted to i1 ; CHECK-NEXT: br i1 %switch.lobit, label %switch.lookup, label %sw.default ; CHECK-NOT: switch i32 } |