Skip to content

Fix vectorized MLIR derivative constants#2962

Open
jacobleft wants to merge 3 commits into
EnzymeAD:mainfrom
jacobleft:jacobleft/fix-vector-constantfp
Open

Fix vectorized MLIR derivative constants#2962
jacobleft wants to merge 3 commits into
EnzymeAD:mainfrom
jacobleft:jacobleft/fix-vector-constantfp

Conversation

@jacobleft

@jacobleft jacobleft commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #2961.

Change

Zero-operand floating constants emitted into derivative expressions now use the derivative shadow type. The generator also propagates that the produced value is already vectorized, preventing the generic vectorization path from broadcasting it a second time.

An equivalent native derivative rule now uses the operand-less representation, so the core MLIR test suite directly exercises this code path.

Regression

test/MLIR/ForwardMode/batched_derivative_constant.mlir fails against this PR's parent while constructing arith.addf(tensor<2x4xf32>, tensor<4xf32>). With this change, it verifies that the generated 1 has type tensor<2x4xf32>.

Invariant

A generated zero-operand derivative constant must have the same shadow type and vectorization state as the tangent expression it participates in.

This replaces the closed #2955.

@jacobleft
jacobleft force-pushed the jacobleft/fix-vector-constantfp branch from 647f4d1 to 092febe Compare July 20, 2026 14:38
@jacobleft
jacobleft marked this pull request as draft July 20, 2026 14:54
@jacobleft
jacobleft force-pushed the jacobleft/fix-vector-constantfp branch from 092febe to a98cc16 Compare July 20, 2026 15:14
@jacobleft
jacobleft marked this pull request as ready for review July 20, 2026 16:02
@vimarsh6739
vimarsh6739 requested a review from wsmoses July 20, 2026 18:26
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.

MLIR: width-forward AD mishandles zero-operand derivative constants

1 participant