Skip to content

Conversation

@quanxi1
Copy link
Contributor

@quanxi1 quanxi1 commented Aug 12, 2025

This PR fixes a probabilistic test failure in the scalar power operation unit test in ZKX.

The original PowOp was designed to reject negative exponents since negative powers require inverse operations. However, it incorrectly rejected unsigned integer exponents with the MSB set to 1, interpreting them as negative values.

Following the MLIR's design choice of builtin operations, instead of imposing the signedness constraints on operand types or checking the MSB of input, we explicitly indicate the intention in the operation name that the operation interprets the exponent input as an unsigned integer by renaming PowOp to PowUIOp.

See MLIR Integer Signedness Semantics Rationale.

Comment has an error and did not reflect actual structure of code logic and so was fixed
Note that `ToMemref` has been changed to `ToBuffer`

LLVM commit used contains the PRs
- llvm/llvm-project#144636
- llvm/llvm-project#144638
which were committed in order to apply changes from `ConstantOp` to `ConstantIntOp`
Patch done to llvm-project:
- Switches int/type ordering of `ConstantIntOp`to standardize with `ConstantOp` argument
   ordering
- Adds constructor for `APInt` types

Note that a `TypedAttr` input still requires `ConstantOp` to be used
patches/ is not a real folder and our patch files are all included in
third-party/llvm-project/
Without this move, pre-commit may need to be run twice
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @quanxi1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a probabilistic test failure in the scalar power operation by refining how exponents are handled. Previously, the power operation incorrectly rejected valid unsigned integer exponents due to a misinterpretation of their sign. The solution involves renaming the operation to PowUIOp to explicitly signify that it expects unsigned integer exponents, thereby removing the ambiguous sign check and aligning the operation with MLIR's established conventions for integer semantics. This ensures correct behavior for power calculations and enhances the robustness of the system.

Highlights

  • Operation Renaming: The core power operation, previously named PowOp, has been renamed to PowUIOp to clearly indicate that it expects an unsigned integer as its exponent.
  • Removal of Erroneous Sign Check: The problematic sign check that incorrectly interpreted unsigned integers with the most significant bit (MSB) set as negative values has been removed from the power operation's conversion logic.
  • MLIR Design Alignment: The changes align the power operation's exponent handling with MLIR's established design principles for integer signedness semantics, promoting consistency and predictability.
  • Probabilistic Test Fix: This fix addresses a probabilistic test failure in the scalar power operation unit test, improving the stability and reliability of the test suite.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@quanxi1
Copy link
Contributor Author

quanxi1 commented Aug 12, 2025

/gemini summary

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a bug in PowOp where large unsigned exponents were incorrectly treated as negative. By renaming the operation to PowUIOp and removing the sign check, the code now clearly communicates its intent to use an unsigned integer for the exponent, aligning with MLIR's design principles. The changes are consistently applied across the operation definition, conversion logic, and tests. The fix is well-reasoned and the implementation is clean.

@fractalyze fractalyze deleted a comment from gemini-code-assist bot Aug 12, 2025
@quanxi1 quanxi1 force-pushed the fix/remove-sign-check-from-power branch from 6206e20 to bd8a7dc Compare August 12, 2025 08:34
@quanxi1 quanxi1 changed the base branch from main to refac/change-arith-constant-op August 12, 2025 08:34
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 4 times, most recently from e8ea60d to 6e14d69 Compare August 12, 2025 09:42
@chokobole
Copy link
Collaborator

Could you add more context to the commit body of fix(field): remove negative exponent assertion from PowOp?
For external reviewers, it’s not immediately clear why the assertion is being removed.

Alternatively, you could squash it with refac(field): rename PowOp to PowUIOp, since the removal of the negative exponent assertion ties directly to the rename—this would help readers connect the reasoning.

You might also consider copying the PR description into the commit body, because it already contains a clear and detailed explanation.

@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 6 times, most recently from 519e2e2 to a35ad9e Compare August 13, 2025 05:34
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 2 times, most recently from 340b12a to c19023e Compare August 13, 2025 05:46
@quanxi1 quanxi1 force-pushed the fix/remove-sign-check-from-power branch from bd8a7dc to 2464719 Compare August 13, 2025 05:54
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch 2 times, most recently from 2a246d9 to a598ee9 Compare August 13, 2025 07:18
@ashjeong ashjeong force-pushed the refac/change-arith-constant-op branch from a598ee9 to e71eef0 Compare August 13, 2025 07:19
…nent

The original PowOp was designed to reject negative exponents since negative
powers require inverse operations. However, it incorrectly rejected unsigned
integer exponents with the MSB set to 1, interpreting them as negative values.

Following the MLIR's design choice of builtin operations, instead of imposing
the signedness constraints on operand types or checking the MSB of input, we
explicitly indicate the intention in the operation name that the operation
interprets the exponent input as an unsigned integer by renaming PowOp to
PowUIOp.
@quanxi1 quanxi1 force-pushed the fix/remove-sign-check-from-power branch from 2464719 to dcf049d Compare August 13, 2025 07:49
@fractalyze fractalyze deleted a comment from gemini-code-assist bot Aug 13, 2025
@quanxi1
Copy link
Contributor Author

quanxi1 commented Aug 13, 2025

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly refactors PowOp to PowUIOp to clarify that it handles unsigned integer exponents, and removes the now-unnecessary sign check. The changes are consistent across the test files, conversion passes, and operation definitions. I have one suggestion to improve the documentation for the new operation.

Copy link
Collaborator

@chokobole chokobole left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@batzor batzor left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ashjeong ashjeong left a comment

Choose a reason for hiding this comment

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

LGTM

@ashjeong ashjeong changed the base branch from refac/change-arith-constant-op to main August 14, 2025 01:34
@chokobole chokobole merged commit 988b2a0 into main Aug 14, 2025
@chokobole chokobole deleted the fix/remove-sign-check-from-power branch August 14, 2025 01:35
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.

5 participants