[llvm] [SimplifyCFG] Simplify switch instruction that has duplicate arms (PR #114262)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 2 00:44:12 PDT 2024
================
@@ -7436,6 +7437,185 @@ static bool simplifySwitchOfCmpIntrinsic(SwitchInst *SI, IRBuilderBase &Builder,
return true;
}
+/// Checking whether two CaseHandle.getCaseSuccessor() are equal depends on
+/// the incoming values of their successor PHINodes.
+/// PHINode::getIncomingValueForBlock has O(|Preds|), so we'd like to avoid
+/// calling this function on each BasicBlock every time isEqual is called,
+/// especially since the same BasicBlock may be passed as an argument multiple
+/// times. To do this, we can precompute a map of PHINode -> Pred BasicBlock ->
+/// IncomingValue and add it in the Wrapper so isEqual can do O(1) checking
+/// of the incoming values.
+struct CaseHandleWrapper {
+ const SwitchInst::CaseHandle Case;
+ DenseMap<PHINode *, DenseMap<BasicBlock *, Value *>> &PhiPredIVs;
+};
+
+namespace llvm {
+template <> struct DenseMapInfo<const CaseHandleWrapper *> {
+ static const CaseHandleWrapper *getEmptyKey() {
+ return reinterpret_cast<CaseHandleWrapper *>(
----------------
dtcxzyw wrote:
```suggestion
return static_cast<CaseHandleWrapper *>(
```
https://github.com/llvm/llvm-project/pull/114262
More information about the llvm-commits
mailing list