[llvm] [SimplifyCFG] Fold the contiguous wrapping cases into ICmp. (PR #161000)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 3 06:35:05 PDT 2025


================
@@ -5718,15 +5718,49 @@ bool SimplifyCFGOpt::simplifyUnreachable(UnreachableInst *UI) {
   return Changed;
 }
 
-static bool casesAreContiguous(SmallVectorImpl<ConstantInt *> &Cases) {
+static bool casesAreContiguous(Value *Condition,
+                               SmallVectorImpl<ConstantInt *> &Cases,
+                               ConstantInt *&ContiguousCasesMin,
+                               ConstantInt *&ContiguousCasesMax,
+                               bool &IsWrapping) {
   assert(Cases.size() >= 1);
 
   array_pod_sort(Cases.begin(), Cases.end(), constantIntSortPredicate);
-  for (size_t I = 1, E = Cases.size(); I != E; ++I) {
-    if (Cases[I - 1]->getValue() != Cases[I]->getValue() + 1)
+  auto Min = Cases.back()->getValue();
+  auto Max = Cases.front()->getValue();
+  auto Offset = Max - Min;
+  auto ContiguousOffset = Cases.size() - 1;
----------------
antoniofrighetto wrote:

No need for auto here, having the type explicit (const APInt&, unsigned) would make the code more readable.

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


More information about the llvm-commits mailing list