Skip to content

Fix crash in TileLoops when redomap input array is also used in postlude#2442

Merged
athas merged 3 commits intomasterfrom
copilot/fix-compiler-crash-after-tiling
May 5, 2026
Merged

Fix crash in TileLoops when redomap input array is also used in postlude#2442
athas merged 3 commits intomasterfrom
copilot/fix-compiler-crash-after-tiling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

mmBlkRegTiling produces invalid IR when a SegMap contains two redomaps sharing an input array — the first redomap is tiled (its input slice goes into tab_inv_stm for shared-memory loading), but the second redomap in the postlude still references that same slice variable, which no longer exists in the epilogue's scope.

Changes

  • src/Futhark/Optimise/BlkRegTiling.hs — Added a guard in matchesBlkRegTile that returns Nothing if any key in tab_inv_stm (tiled redomap inputs) is also free in the postlude code (code2'' <> code2). This causes mmBlkRegTiling to decline and fall through to tileInKernelBody, which handles the case correctly by placing invariant prelude definitions in the outer kernel body where they remain in scope.

  • tests/tiling/issue2467.fut — Regression test using a matrix multiply + entrywise divide pattern that triggers the two-redomap-sharing-an-input scenario:

entry main W A WH =
  let W_TA  = matmul (transpose W) A
  let W_TWH = matmul (transpose W) WH
  in matdiv_entrywise W_TA W_TWH

Previously this crashed with Use of unknown variable as_transformed_row_... after the tile-loops pass.

Copilot AI linked an issue May 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix compiler crash after tiling Fix crash in TileLoops when redomap input array is also used in postlude May 5, 2026
Copilot finished work on behalf of athas May 5, 2026 09:28
Copilot AI requested a review from athas May 5, 2026 09:28
@athas
Copy link
Copy Markdown
Member

athas commented May 5, 2026

This is a pretty obvious fix, close to what I would have written myself. My only worry is whether it is too conservative, and would stop tiling in other cases. However, it seems clear to me that all cases caught by this check would previously result in invalid code.

@athas athas marked this pull request as ready for review May 5, 2026 09:59
@athas athas merged commit 9db0cb1 into master May 5, 2026
31 checks passed
@athas athas deleted the copilot/fix-compiler-crash-after-tiling branch May 5, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler crash after tiling

2 participants