[Mlir-commits] [mlir] [mlir][ControlFlow] Improve time complexity of RegionBranchOpInterface canonicalization patterns (PR #186114)

Matthias Springer llvmlistbot at llvm.org
Thu Mar 12 08:57:08 PDT 2026


================
@@ -668,6 +675,10 @@ static llvm::SmallDenseSet<Value> computeReachableValuesFromSuccessorInput(
     auto it = inputToOperands.find(next);
     if (it == inputToOperands.end()) {
       reachableValues.insert(next);
+      // Early exit: stop traversal if more reachable values than the caller
+      // cares about have been found.
+      if (maxReachableValues > 0 && reachableValues.size() > maxReachableValues)
+        return reachableValues;
----------------
matthias-springer wrote:

It's not correct to just return the first reachable value. The pattern below should not apply if there is more than 1 reachable value. In that case, this function should signal an error. That's why I suggest to give this function a `LogicalResult` return value.

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


More information about the Mlir-commits mailing list