Skip to content

[complex-math-expander] Add mode option and basic complex arithmetic decomposition#2916

Open
brucechanglongxu wants to merge 1 commit intoopenxla:mainfrom
brucechanglongxu:complex-math-expander-arithmetic-decomp
Open

[complex-math-expander] Add mode option and basic complex arithmetic decomposition#2916
brucechanglongxu wants to merge 1 commit intoopenxla:mainfrom
brucechanglongxu:complex-math-expander-arithmetic-decomp

Conversation

@brucechanglongxu
Copy link
Copy Markdown

@brucechanglongxu brucechanglongxu commented Mar 18, 2026

Per the discussion in #2913, this adds a mode flag to stablehlo-complex-math-expander so the pass can also decompose basic complex arithmetic (add, subtract, multiply, divide, negate) into real-valued ops — useful for backends without native complex support.

--stablehlo-complex-math-expander=mode=precision (default) keeps current behavior (only transcendental ops like log/sqrt/exp/log1p). --stablehlo-complex-math-expander=mode=all additionally lowers the basic arithmetic ops.

The new patterns are C++ OpRewritePatterns rather than TableGen DRR so they can be conditionally registered based on the mode, and stay separate from the functional_algorithms-generated precision patterns. Division uses Smith's method to avoid blowup when one component of the divisor dominates.

Also exposes populateStablehloComplexArithmeticExpanderPatterns for anyone who wants to use these patterns outside the pass.

Tests cover both modes, f32/f64, dynamic shapes, scalars, and multi-dim tensors.

Closes #2913

…decomposition

Add a `mode` option to the `stablehlo-complex-math-expander` pass to
distinguish between:
- `precision` (default): Expands only precision-sensitive transcendental
  ops (log, sqrt, exp, log_plus_one) using numerically stable algorithms.
- `all`: Additionally decomposes basic complex arithmetic (add, subtract,
  multiply, divide, negate) into real-valued operations, for hardware
  backends that lack native complex number support.

The arithmetic decomposition patterns are implemented as C++ RewritePattern
classes, keeping them cleanly separated from the precision patterns
generated via functional_algorithms. Complex division uses Smith's method
for numerical stability.

A new `populateStablehloComplexArithmeticExpanderPatterns` API is exposed
for downstream users who want to use these patterns independently.

Addresses openxla#2913
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.

Adding traditional element-wise operations to stablehlo-complex-math-expander

1 participant