[llvm] [SimplifyCFG] Convert switch to cmp/select sequence (PR #82795)
Thomas Symalla via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 04:03:35 PDT 2024
================
@@ -6197,6 +6197,268 @@ static bool trySwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
return true;
}
+// The first field contains the value that the switch produces when a certain
+// case group is selected, and the second field is a vector containing the
+// cases composing the case group.
+using SwitchCaseResultVectorTy2 =
+ SmallVector<std::pair<Value *, SmallVector<Value *, 4>>, 2>;
+
+// The first field contains the phi node that generates a result of the switch
+// and the second field contains the value generated for a certain case in the
+// switch for that PHI.
+using SwitchCaseResultsTy2 = SmallVector<std::pair<PHINode *, Value *>, 4>;
+
+using PHINodeToCaseEntryValueMapTy =
+ std::map<PHINode *, SmallVector<std::pair<ConstantInt *, Value *>, 4>>;
+
+// Helper function that checks if all PHI Nodes have default value
+bool allPHINodesHaveDefaultValue(const SwitchCaseResultsTy2 &Results) {
+ for (const auto &Pair : Results)
+ if (Pair.second == nullptr)
+ return false;
+ return true;
+}
+
+static bool getCaseResultsWithoutConstants(
+ SwitchInst *SI, BasicBlock *CaseDest, BasicBlock **CommonDest,
----------------
tsymalla wrote:
```suggestion
SwitchInst *SI, BasicBlock *CaseDest, BasicBlock *&CommonDest,
```
https://github.com/llvm/llvm-project/pull/82795
More information about the llvm-commits
mailing list