[Mlir-commits] [mlir] [mlir][dataflow] Deduplicate data-flow solver worklist items (PR #221983)

Yoni Katzuv llvmlistbot at llvm.org
Mon Sep 14 04:38:34 PDT 2026


YoniKF wrote:

@Hardcode84 I came to implement these changes after seeing an out-of-tree (internal) analysis accounting for a significant percentage of our pipeline's runtime, on some edge inputs. It is a dense forward data-flow analysis which tracks uses of SSA values to verify [affine usage](https://en.wikipedia.org/wiki/Substructural_type_system#Affine_type_systems) (at most one use on any execution path).

In-tree, I found the test `NextAccessAnalysis` which has similar characteristics to my analysis. I think that performance improvement is best demonstrated by the number of times various transfer functions are called. 
In the following example (switch with 49 case + default, inspired by `mlir/test/Analysis/DataFlow/test-next-access.mlir`), this PR reduces the number of calls to `NextAccessAnalysis::visitRegionBranchControlFlowTransfer` from 5100 to 150.
The transfer function is called for each case/default region on each visit to `scf.index_switch`; this op is enqueued by each case/default, meaning O(N^2) calls before the PR, but only O(N) calls after.

```mlir
// RUN: mlir-opt %s --test-next-access --debug-only=test-next-access 2>&1 |\
// RUN:             grep -c visitRegionBranchControlFlowTransfer

func.func @switch(%arg: index, %arg0: memref<f32>) {
  memref.load %arg0[] {name = "pre"}: memref<f32>

  scf.index_switch %arg
  case 0 {
    memref.load %arg0[] {name = "case 0"} : memref<f32>
    scf.yield
  }
  // 47 more cases...
  case 48 {
    memref.load %arg0[] {name = "case 48"} : memref<f32>
    scf.yield
  }
  default {
    memref.load %arg0[] {name = "default"} : memref<f32>
    scf.yield
  }

  memref.load %arg0[] {name = "post"} : memref<f32>
  return
}
```

I'm not sure whether it makes sense to commit this as a test case, but I did add `wide_fan_in` under `mlir/test/Analysis/test-foo-analysis.mlir` which shows only 1+1 visits to a join point of 5 predecessors, instead of 1+5 before this PR.

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


More information about the Mlir-commits mailing list