[Mlir-commits] [mlir] [MLIR][Analysis] Fix incorrect RegionBranchOpInterface API usage in SliceWalk (PR #188758)

Hocky Yudhiono llvmlistbot at llvm.org
Wed Apr 1 00:58:44 PDT 2026


================
@@ -68,11 +68,17 @@ mlir::getControlFlowPredecessors(Value value) {
     if (!regionOp)
       return std::nullopt;
     // Add the control flow predecessor operands to the work list.
-    RegionSuccessor region = RegionSuccessor::parent();
+    RegionSuccessor parentSuccessor = RegionSuccessor::parent();
+    // Find the position of `opResult` in the successor inputs of the parent.
+    // `getPredecessorValues` indexes into the successor inputs, not into the
+    // op results directly, since some results may not be successor inputs.
+    ValueRange successorInputs = regionOp.getSuccessorInputs(parentSuccessor);
+    auto it = llvm::find(successorInputs, opResult);
+    if (it == successorInputs.end())
+      return std::nullopt;
     SmallVector<Value> predecessorOperands;
-    // TODO (#175168): This assumes that there are no non-successor-inputs
-    // in front of the op result.
-    regionOp.getPredecessorValues(region, opResult.getResultNumber(),
+    regionOp.getPredecessorValues(parentSuccessor,
----------------
hockyy wrote:

<img width="738" height="275" alt="Image" src="https://github.com/user-attachments/assets/6e5a9d46-b5be-4ba1-a10b-fb2e4aa1da6f" />
So this getSuccessorInputs for example is ignoring the result of the first one, that's why the legacy `opResult.getResultNumber()` is not accurate -- the old function would perceive this as `1` instead of `0`

<img width="843" height="250" alt="Image" src="https://github.com/user-attachments/assets/8077ccc0-739d-4817-a9ae-989138426254" />

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


More information about the Mlir-commits mailing list