Skip to content

[water] verify index expr step/strire are positive#1051

Open
ftynse wants to merge 1 commit intousers/ftynse/non-unit-stepfrom
users/ftynse/positive-step
Open

[water] verify index expr step/strire are positive#1051
ftynse wants to merge 1 commit intousers/ftynse/non-unit-stepfrom
users/ftynse/positive-step

Conversation

@ftynse
Copy link
Contributor

@ftynse ftynse commented Mar 5, 2026

Add a verifier that index expression step and stride are strictly
positive to avoid semantically undefined behavior (what does it mean to
have a 0-element piece of the tensor? stride zero is hidden
broadcasting, negative stride is hidden reversal, both are deterimental
to dependence analysis).

Closes #1012.

Add a verifier that index expression step and stride are strictly
positive to avoid semantically undefined behavior (what does it mean to
have a 0-element piece of the tensor? stride zero is hidden
broadcasting, negative stride is hidden reversal, both are deterimental
to dependence analysis).

Closes #1012.

Signed-off-by: Alex Zinenko <git@ozinenko.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds verification to reject semantically undefined Wave index mappings by requiring index-expression step and stride to be strictly positive when they can be folded to a concrete value (with hyperparameters substituted), improving correctness for dependence analysis.

Changes:

  • Add Wave dialect verification for strictly-positive step/stride and retain “at most one non-unit step” enforcement when foldable.
  • Add MLIR negative tests covering zero/negative step and stride.
  • Update ElementsPerThread inference commentary and adjust an inference test setup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
water/lib/Dialect/Wave/IR/WaveDialect.cpp Introduces verifier helpers to enforce positive step/stride and integrates them into dialect verification flow.
water/test/Dialect/Wave/ops-invalid.mlir Adds invalid IR tests asserting new verifier diagnostics for zero/negative step/stride.
water/lib/Dialect/Wave/Transforms/InferTypes.cpp Updates TODO commentary around redundancy with verifiers and hyperparameter presence.
water/test/Dialect/Wave/propagate-elements-per-thread.mlir Adjusts a test function’s attributes related to hyperparameters for inference-pass behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +533 to 534
if (failed(verifyIndexStepAndStride(op, hyperparams)))
return WalkResult::interrupt();
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

verifyIndexStepAndStride is only invoked while verifying the presence of the wave.hyperparameters attribute. This means ops without wave.hyperparameters can still contain an index mapping with constant step/stride <= 0 (which evaluateMapWithHyperparams can fold even without hyperparams), and they will pass verification. To fully enforce the “step/stride must be strictly positive” rule, consider running this check from the HasWaveIndexMapping trait verifier (verifyWaveIndexMappings) and using an empty/default hyperparam set when none is provided (similar to verifyIndexElementsPerThread).

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@martin-luecke martin-luecke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just typos

  • typo in PR title: strire → stride
  • typo in body: deterimental → detrimental

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.

3 participants