Skip to content

feat(LLVM): parse llvm.call_intrinsic - #1407

Merged
tobiasgrosser merged 4 commits into
mainfrom
tobias/llvm_call_intrinsic
Sep 7, 2026
Merged

feat(LLVM): parse llvm.call_intrinsic#1407
tobiasgrosser merged 4 commits into
mainfrom
tobias/llvm_call_intrinsic

Conversation

@tobiasgrosser

@tobiasgrosser tobiasgrosser commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Add llvm.call_intrinsic, the op MLIR uses for LLVM intrinsics without a dedicated op, with the properties clang emits: intrin, operandSegmentSizes, op_bundle_sizes, op_bundle_tags, fastmathFlags, arg_attrs and res_attrs. The verifier mirrors MLIR's: the name must start with llvm., at most one result, no regions, operandSegmentSizes must be an i32 array matching the operands, and the bundle sizes and tags must be consistent. The bundle checks are shared with llvm.intr.assume through a new verifyOperandBundles helper, which also makes that op reject non-i32 sizes and missing or non-string tags the same way. Effects stay .unknown, since they depend on the intrinsic name.

🤖 Generated with Claude Code

@tobiasgrosser tobiasgrosser self-assigned this Sep 7, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@tobiasgrosser
tobiasgrosser force-pushed the tobias/llvm_call_intrinsic branch from 5fb4c84 to 224baef Compare September 7, 2026 06:23
@tobiasgrosser tobiasgrosser changed the title feat(LLVM): add llvm.call_intrinsic feat(LLVM): parse llvm.call_intrinsic Sep 7, 2026
@tobiasgrosser tobiasgrosser added the LLVM The LLVM Dialect label Sep 7, 2026

@mafeguimaraes mafeguimaraes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

tobiasgrosser and others added 2 commits September 7, 2026 22:40
Share the operand bundle checks of llvm.intr.assume through a new
verifyOperandBundles helper, so call_intrinsic also rejects missing or
non-string tags and non-i32 sizes. Require the llvm. name prefix and a
region-free op, check operandSegmentSizes is i32, and reuse the fast-math
parser. The negative tests now also run MLIR_INVALID.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
throw "Expected 0 successors"
pure ()
| .call_intrinsic => do
op.checkIsNonNullIntegerType ctx opIn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This only checks that it is not a i0. So things like vector, index, felt, are still allowed from this.
I'm pretty sure that most other operations are also buggy in that way :/

@math-fehr math-fehr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There is a bug due to OperationPtr.checkIsNonNullIntegerType being wrong, but otherwise I think it's fine so far

checkIsNonNullIntegerType only rejects i0, so operands and results of
type index, felt or similar slipped through. Add
Attribute.isLLVMCompatibleType and verifyLLVMCompatibleTypes to the
verifier utilities and apply them to call_intrinsic.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@tobiasgrosser
tobiasgrosser added this pull request to the merge queue Sep 7, 2026
Merged via the queue into main with commit 5c27695 Sep 7, 2026
6 checks passed
@tobiasgrosser
tobiasgrosser deleted the tobias/llvm_call_intrinsic branch September 7, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

LLVM The LLVM Dialect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants