Skip to content

Add not_int intrinsic for for-loop iteration support#107

Open
0xtaruhi wants to merge 2 commits intoJuliaGPU:mainfrom
0xtaruhi:fix/not-int-for-loops
Open

Add not_int intrinsic for for-loop iteration support#107
0xtaruhi wants to merge 2 commits intoJuliaGPU:mainfrom
0xtaruhi:fix/not-int-for-loops

Conversation

@0xtaruhi
Copy link
Contributor

@0xtaruhi 0xtaruhi commented Mar 6, 2026

Summary

Julia desugars for i in 1:n into Core.Intrinsics.not_int to negate the loop-exit condition. Without handling this intrinsic, any kernel using for loops hits IRError("Unhandled Julia intrinsic: not_int").

Implementation: not_int(x)xori(x, allones) where:

  • Bool → xori(x, true) (logical negation)
  • Integer → xori(x, -1) (bitwise complement, all bits set)

Changes

File Change
src/compiler/intrinsics/julia.jl not_int dispatch + emit_not_int!
test/codegen/operations.jl ~ (bitwise NOT) codegen test
test/execution/basic.jl ~ execution test + 3 for-loop execution tests

Tests

  • map(~, tile) bitwise NOT correctness
  • for i in Int32(1):n_iters — literal bound
  • for i in Int32(1):Int32(n_iters)ct.Constant bound
  • for j in Int32(1):len — dynamic bound from scalar indexing

Depends on

- Fix ShLIOp encoding to include overflow parameter
- Refactor andi/ori/xori emit to use shared emit_binop! helper
- Add codegen tests for bitwise ops (andi, ori, xori, shli, shri)
- Add execution tests for bitwise ops to catch tileiras compilation issues
- Handle Core.Intrinsics.not_int via xori(x, allones) in julia.jl
- Enables Julia's standard `for i in 1:n` loops in kernels
- Add bitwise NOT (~) codegen test
- Add execution tests: for-loop with literal, constant, and dynamic bounds
@0xtaruhi 0xtaruhi force-pushed the fix/not-int-for-loops branch from 48bf507 to 6e038ef Compare March 6, 2026 04: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.

1 participant