Skip to content

Add ScatterOp no-op simplification patterns#2920

Open
brucechanglongxu wants to merge 1 commit intoopenxla:mainfrom
brucechanglongxu:add-scatter-op-simplification
Open

Add ScatterOp no-op simplification patterns#2920
brucechanglongxu wants to merge 1 commit intoopenxla:mainfrom
brucechanglongxu:add-scatter-op-simplification

Conversation

@brucechanglongxu
Copy link

ScatterOp had zero simplification patterns — even trivially dead
scatters were being left in the IR. This adds two no-op patterns to
StablehloAggressiveSimplification:

  1. ScatterOpEmptyIndices — scatter_indices has no scatter points (a
    non-index_vector_dim axis is 0), so nothing gets scattered. The
    inputs pass through.

  2. ScatterOpZeroExtentUpdates — all update tensors have zero elements,
    same result.

These mirror the existing DynamicUpdateSliceOp_RemoveNoop /
ConcatenateOpRemoveEmpty patterns. More interesting patterns (e.g.
full-replace folding when the update body is a trivial return of arg1)
can come later, but these two cover the low-hanging fruit.

Tests included for both patterns plus a negative case to make sure we
don't over-simplify.

Toward #2736

Two new patterns in StablehloAggressiveSimplification:

- ScatterOpEmptyIndices: when scatter_indices has zero scatter points
  along any non-index_vector_dim axis, the scatter is a no-op and the
  inputs pass through unchanged.

- ScatterOpZeroExtentUpdates: when all update tensors have zero
  elements, the scatter does nothing.

Both follow the existing convention for no-op detection (cf.
DynamicUpdateSliceOp_RemoveNoop, ConcatenateOpRemoveEmpty).

Toward openxla#2736
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