-
Notifications
You must be signed in to change notification settings - Fork 13
fix: make fast-math toggles work #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.py
tests/test_llvmlite_helpers.py
|
|
@xmnlab @yuvimittal Please review this |
|
hi @omsherikar , thanks for working on that. |
Sure @xmnlab, Thank you! |
|
@xmnlab Please have a look into it |
|
@yuvimittal Have a look at it |
| """Attach fast-math flags when enabled and applicable.""" | ||
| if not self._fast_math_enabled: | ||
| return | ||
| ty = inst.type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inst.flags might be None, immutable or absent, so it can cause attributeError or TypeError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback @yuvimittal. and sorry for the delay .Should I handle it with a try-except block?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added defensive handling using getattr and try/except so it won't crash if flags is None or immutable.
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.py
tests/test_llvmlite_helpers.py
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes issue #136 by implementing fast-math flag support for floating-point operations in the LLVM IR builder. The implementation adds a set_fast_math method to track fast-math state and a helper to conditionally apply the "fast" flag to floating-point instructions.
Key Changes:
- Added
set_fast_math(enabled: bool)method and_fast_math_enabledinstance variable to track fast-math state - Implemented
_apply_fast_math(inst)helper that checks instruction types and applies flags appropriately - Integrated fast-math flag application into all floating-point operations (fadd, fsub, fmul, fdiv, fma)
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/irx/builders/llvmliteir.py | Adds fast-math state tracking, helper method, and integrates flag application into FP operations |
| tests/test_llvmlite_helpers.py | Adds unit test verifying fast-math flags are correctly applied when enabled and absent when disabled |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.py
tests/test_llvmlite_helpers.pyLGTM! |
66644bd to
843fe25
Compare
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.pyBug: fast-math flags are applied to inst.flags, but in llvmlite FP ops/calls use the fastmath attribute, not flags. As written, this likely no-ops for fadd/fsub/fmul/fdiv/call. Please set inst.fastmath (and assign, not just mutate) and handle vector element attr robustly. Suggested fix: (L.435) tests/test_llvmlite_helpers.py
|
|
@yuvimittal Please review the changes |
Pull Request description
This PR fixes issue #136 by implementing the missing
set_fast_mathmethod and adding support for applying fast-math flags to floating-point instructions. Previously, calls toself.set_fast_math(True/False)invisit(BinaryOp)would crash because the method did not exist inLLVMLiteIRVisitor.The fix includes:
set_fast_math(enabled: bool)to track fast-math state_apply_fast_math(inst)to conditionally attach the"fast"flag to floating-point instructionsfadd,fsub,fmul,fdiv,fma)Solve #136
How to test these changes
makim tests.unitto execute the unit test suitetest_set_fast_math_marks_float_opsverifies that fast-math flags are applied to floating-point operations whenset_fast_math(True)is calledset_fast_math(False)is calledPull Request checklists
This PR is a:
About this PR:
Author's checklist:
complexity.
Additional information
The implementation tracks fast-math state via
self._fast_math_enabledand applies flags only to floating-point instructions (both scalar and vector). The_apply_fast_mathhelper checks if the instruction type is a floating-point type before attaching the"fast"flag, ensuring that integer operations are not affected.Reviewer's checklist
Copy and paste this template for your review's note: