[llvm] [SimplifyCFG] Simplify switch instruction that has duplicate arms (PR #114262)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 23:51:14 PST 2024


================
@@ -7436,6 +7437,176 @@ static bool simplifySwitchOfCmpIntrinsic(SwitchInst *SI, IRBuilderBase &Builder,
   return true;
 }
 
+/// Checking whether two CaseHandle.getCaseSuccessor() are equal depends on
+/// the BasicBlock and the incoming values of their successor PHINodes.
+/// PHINode::getIncomingValueForBlock is 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;
----------------
dtcxzyw wrote:

I see. We can use `SwitchInst::getSuccessor/SwitchInst::setSuccessor` here. The default dest BB is the first successor.
 

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


More information about the llvm-commits mailing list