)]}'
{
  "commit": "7c6537ba13a69c9838153404cd19156044e95283",
  "tree": "c84cd2b979fd7f0ded3254a11f29cebddda500e0",
  "parents": [
    "353c60a2e426fa50eac2bca5b8be15c57d3bbdc0"
  ],
  "author": {
    "name": "jakobknauer",
    "email": "knauer@roofline.ai",
    "time": "Thu Nov 12 15:05:07 2026 +0100"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Thu Nov 12 14:05:07 2026 +0000"
  },
  "message": "[LLVMCPU] avoid fusing invariant reduction producers (#25201)\n\nKeep invariant tensor Linalg reductions outside reduction tile loops,\ninstead of fusing it with the consumer inside the loop, which would\nrepeat the same computation for each consumer tile. This avoids for\nexample recomputing whole-row maxima during tiled softmax sums.\n\nIR excerpt of softmax without change (max inside the loop)\n```\n%15 \u003d tensor.empty(%14) : tensor\u003c?xf32\u003e\n%16 \u003d linalg.fill {lowering_config \u003d #iree_cpu.lowering_config\u003cvector_common_parallel \u003d [4]\u003e} ins(%cst : f32) outs(%15 : tensor\u003c?xf32\u003e) -\u003e tensor\u003c?xf32\u003e\n%17 \u003d scf.for %arg4 \u003d %c0 to %6 step %c4 iter_args(%arg5 \u003d %16) -\u003e (tensor\u003c?xf32\u003e) {\n  ...\n  %27 \u003d linalg.generic {indexing_maps \u003d [affine_map\u003c(d0, d1) -\u003e (d0, d1)\u003e, affine_map\u003c(d0, d1) -\u003e (d0)\u003e], iterator_types \u003d [\"parallel\", \"reduction\"]} ins(%extracted_slice_6 : tensor\u003c?x?xf32\u003e) outs(%26 : tensor\u003c?xf32\u003e) attrs \u003d  {lowering_config \u003d #iree_cpu.lowering_config\u003cvector_common_parallel \u003d [4, 0], vector_reduction \u003d [0, 4]\u003e} {\n  ^bb0(%in: f32, %out: f32):\n    %29 \u003d arith.maxnumf %in, %out : f32\n    linalg.yield %29 : f32\n  } -\u003e tensor\u003c?xf32\u003e\n  %extracted_slice_7 \u003d tensor.extract_slice %arg5[0] [%14] [1] : tensor\u003c?xf32\u003e to tensor\u003c?xf32\u003e\n  %28 \u003d linalg.generic {...} ins(%extracted_slice_5, %27 : tensor\u003c?x?xf32\u003e, tensor\u003c?xf32\u003e) outs(%extracted_slice_7 : tensor\u003c?xf32\u003e) attrs \u003d  {...} {\n  ^bb0(%in: f32, %in_8: f32, %out: f32):\n    %29 \u003d arith.subf %in, %in_8 : f32\n    %30 \u003d math.exp %29 : f32\n    %31 \u003d arith.addf %30, %out : f32\n    linalg.yield %31 : f32\n  } -\u003e tensor\u003c?xf32\u003e\n  %inserted_slice \u003d tensor.insert_slice %28 into %arg5[0] [%14] [1] : tensor\u003c?xf32\u003e into tensor\u003c?xf32\u003e\n  scf.yield %inserted_slice : tensor\u003c?xf32\u003e\n}\n```\n\nWith the change:\n```\n%15 \u003d affine.apply affine_map\u003c()[s0, s1] -\u003e (s0 + s1)\u003e()[%arg2, %arg0]\n%extracted_slice_2 \u003d tensor.extract_slice %9[%15, 0] [%14, %6] [1, 1] : tensor\u003c?x?xf32\u003e to tensor\u003c?x?xf32\u003e\n%16 \u003d tensor.empty(%14) : tensor\u003c?xf32\u003e\n%17 \u003d linalg.fill {lowering_config \u003d #iree_cpu.lowering_config\u003cvector_common_parallel \u003d [4]\u003e} ins(%cst_0 : f32) outs(%16 : tensor\u003c?xf32\u003e) -\u003e tensor\u003c?xf32\u003e\n%18 \u003d linalg.generic {indexing_maps \u003d [affine_map\u003c(d0, d1) -\u003e (d0, d1)\u003e, affine_map\u003c(d0, d1) -\u003e (d0)\u003e], iterator_types \u003d [\"parallel\", \"reduction\"]} ins(%extracted_slice_2 : tensor\u003c?x?xf32\u003e) outs(%17 : tensor\u003c?xf32\u003e) attrs \u003d  {lowering_config \u003d #iree_cpu.lowering_config\u003cvector_common_parallel \u003d [4, 0], vector_reduction \u003d [0, 4]\u003e} {\n^bb0(%in: f32, %out: f32):\n  %26 \u003d arith.maxnumf %in, %out : f32\n  linalg.yield %26 : f32\n} -\u003e tensor\u003c?xf32\u003e\n%19 \u003d tensor.empty(%14) : tensor\u003c?xf32\u003e\n%20 \u003d linalg.fill {lowering_config \u003d #iree_cpu.lowering_config\u003cvector_common_parallel \u003d [4]\u003e} ins(%cst : f32) outs(%19 : tensor\u003c?xf32\u003e) -\u003e tensor\u003c?xf32\u003e\n%21 \u003d scf.for %arg4 \u003d %c0 to %6 step %c4 iter_args(%arg5 \u003d %20) -\u003e (tensor\u003c?xf32\u003e) {\n  ...\n  %28 \u003d linalg.generic {indexing_maps \u003d [affine_map\u003c(d0, d1) -\u003e (d0, d1)\u003e, affine_map\u003c(d0, d1) -\u003e (d0)\u003e, affine_map\u003c(d0, d1) -\u003e (d0)\u003e], iterator_types \u003d [\"parallel\", \"reduction\"]} ins(%extracted_slice_6, %extracted_slice_7 : tensor\u003c?x?xf32\u003e, tensor\u003c?xf32\u003e) outs(%extracted_slice_8 : tensor\u003c?xf32\u003e) attrs \u003d  {lowering_config \u003d #iree_cpu.lowering_config\u003cdistribution \u003d [32, 0], vector_common_parallel \u003d [4, 0], vector_reduction \u003d [0, 4]\u003e} {\n  ^bb0(%in: f32, %in_9: f32, %out: f32):\n    %29 \u003d arith.subf %in, %in_9 : f32\n    %30 \u003d math.exp %29 : f32\n    %31 \u003d arith.addf %30, %out : f32\n    linalg.yield %31 : f32\n  } -\u003e tensor\u003c?xf32\u003e\n  %inserted_slice \u003d tensor.insert_slice %28 into %arg5[0] [%14] [1] : tensor\u003c?xf32\u003e into tensor\u003c?xf32\u003e\n  scf.yield %inserted_slice : tensor\u003c?xf32\u003e\n}\n```\n\nLICM does not move the max out of the loop because it only runs after\nthe max computation has been tiled, at which point LICM cannot prove\ninvariance anymore.\n\nAssisted-by: OpenAI Codex\n\n---------\n\nSigned-off-by: Jakob Knauer \u003cknauer@roofline.ai\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "90f2e5bafee2bda6b2a37ea1a58295e61ce0c314",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/BUILD.bazel",
      "new_id": "b7c6061a59c423bb78bfc9b52c753d72f4a96dbd",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/BUILD.bazel"
    },
    {
      "type": "modify",
      "old_id": "910c739fd457e5af5dd9ec80bc2c04766072e999",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/CMakeLists.txt",
      "new_id": "7dc8ab9b7f233f5cb5cc621816817f2f153c439c",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "1ce911349f82d032b7482e9f7c96ea8af42fd717",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileAndFuseProducerConsumer.cpp",
      "new_id": "32a6f9ab4fc56b09f531a153da1f6f48c5eb6b2b",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/LLVMCPUTileAndFuseProducerConsumer.cpp"
    },
    {
      "type": "modify",
      "old_id": "837115daa63f4b07d62e8a269ca50d8df1a68890",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/test/BUILD.bazel",
      "new_id": "a446c0aae5db38beb7f46fe2c007b1e387df59d9",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/test/BUILD.bazel"
    },
    {
      "type": "modify",
      "old_id": "8d75ee9949faac2476a3581822354ce8fa1a19eb",
      "old_mode": 33188,
      "old_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/test/CMakeLists.txt",
      "new_id": "9512cf6fcd15c7d5e15e441d4b7381dba814d886",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/test/CMakeLists.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "2ae975ad5915cfc40caa4ef150a52a0b4736b8fc",
      "new_mode": 33188,
      "new_path": "compiler/src/iree/compiler/Codegen/LLVMCPU/test/tile_and_fuse_invariant_reduction.mlir"
    }
  ]
}
