[llvm] [SimplifyCFG] Find the minimal table considering overflow in `switchToLookupTable` (PR #67885)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 06:09:00 PDT 2023


================
@@ -6519,17 +6518,55 @@ static bool SwitchToLookupTable(SwitchInst *SI, IRBuilder<> &Builder,
   SmallDenseMap<PHINode *, Type *> ResultTypes;
   SmallVector<PHINode *, 4> PHIs;
 
-  for (SwitchInst::CaseIt E = SI->case_end(); CI != E; ++CI) {
-    ConstantInt *CaseVal = CI->getCaseValue();
-    if (CaseVal->getValue().slt(MinCaseVal->getValue()))
-      MinCaseVal = CaseVal;
-    if (CaseVal->getValue().sgt(MaxCaseVal->getValue()))
-      MaxCaseVal = CaseVal;
+  SmallVector<ConstantInt *, 8> CaseVals;
----------------
DianQK wrote:

I changed to
```
  SmallVector<ConstantInt *, 8> CaseVals(llvm::map_range(
      SI->cases(), [](const auto &C) { return C.getCaseValue(); }));
```

https://github.com/llvm/llvm-project/pull/67885


More information about the llvm-commits mailing list