fix: make fast-math toggles work#140
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.
inst.flags might be None, immutable or absent, so it can cause attributeError or TypeError.
There was a problem hiding this comment.
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.
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.
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 |
|
@omsherikar LGTM, please push empty commit to check CI/CD |
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.pyChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}} tests/test_llvmlite_helpers.pyChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}} |
@yuvimittal All checks passed |
OSL ChatGPT ReviewerNOTE: This is generated by an AI program, so some comments may not make sense. src/irx/builders/llvmliteir.pyChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}} tests/test_llvmlite_helpers.pyChatGPT was not able to review the file. Error: Error code: 429 - {'error': {'message': 'You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.', 'type': 'insufficient_quota', 'param': None, 'code': 'insufficient_quota'}} |
|
LGTM! @omsherikar thanks for working on that |
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: