Skip to content

EnzymeHLOOpt: DUSDUSSubsuming moves slices only when it replaces the DUS - #3470

Merged
wsmoses merged 1 commit into
mainfrom
pb/dusdus-replace-before-moving-slices
Oct 12, 2026
Merged

wsmoses merged 1 commit into
mainfrom
pb/dusdus-replace-before-moving-slices

Conversation

@wsmoses

@wsmoses wsmoses commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

DUSDUSSubsuming, on two stacked dynamic update slices, does two things:

  1. It moves slices of the inner update whose values don't change onto the outer one, so the inner update dies once the outer one is replaced.
  2. It replaces the outer update with a piecewise select.

It reported success if either happened. When the outer update can't be replaced (here: partial updates whose sources don't span the result), it still moved the slices. SliceOfDynamicUpdate then moves each slice back, since a slice of a DUS that's clear of its update is a slice of the DUS's operand. The two patterns traded the slices forever:

APPLIED DUSDUSSubsuming on stablehlo.dynamic_update_slice
APPLIED SliceOfDynamicUpdate on stablehlo.slice
APPLIED SliceOfDynamicUpdate on stablehlo.slice
APPLIED DUSDUSSubsuming on stablehlo.dynamic_update_slice
...

Fix: make the replacement first and move the slices only when it's made. rematerializeByPiecewiseSelect returns null before creating any op when it can't build the replacement, so trying it first leaves the IR untouched on failure.

Found via: MFEM bilininteg_vecdiffusion_pa.cpp. With #3444, one function's enzyme-hlo-opt never finished (> 10 min); with this fix it takes about a second. The cycle is in main's patterns: main hangs on the IR #3444 produces there, and on the 8-line test added here.

Test: new dusdus_slice_clear_of_update.mlir with full-line goldens. Main doesn't terminate on it; with this fix the IR is left unchanged. All 42 *dus* lit tests pass. Full local lit: 1506/1509. The other three fail on main as well: mem2reg_copied_field and mem2reg_split_aggregate (fixed by #3471), and //test:neuralgcm_test, which runs out of memory on our 32 GB GPUs.

🤖 Generated with Claude Code

https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD

DUSDUSSubsuming moves the slices of the inner of two dynamic update
slices whose value does not change onto the outer one, so that the
inner one dies once the outer is replaced by a piecewise select. It
counted the move as progress on its own, also when the outer update
could not be replaced; SliceOfDynamicUpdate then moves each such slice
back (a slice of a DUS clear of its update is a slice of its operand),
and the two traded the slices forever.

Make the replacement first (it creates nothing when it cannot be made)
and move the slices only when it is made.

On MFEM's bilininteg_vecdiffusion_pa, enzyme-hlo-opt never finished one
function once an unrelated pattern exposed such a pair; it now takes
about a second.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD
@wsmoses
wsmoses requested a review from ftynse October 12, 2026 02:50
@wsmoses
wsmoses merged commit 73603ba into main Oct 12, 2026
21 of 31 checks passed
@wsmoses
wsmoses deleted the pb/dusdus-replace-before-moving-slices branch October 12, 2026 03:00
@codecov

codecov Bot commented Oct 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 29.98%. Comparing base (fb49aed) to head (54db176).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3470      +/-   ##
==========================================
+ Coverage   29.92%   29.98%   +0.06%     
==========================================
  Files         241      241              
  Lines       48628    48670      +42     
==========================================
+ Hits        14551    14596      +45     
+ Misses      34077    34074       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant