Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1120 +/- ##
==========================================
- Coverage 93.13% 93.12% -0.01%
==========================================
Files 32 32
Lines 8574 8625 +51
==========================================
+ Hits 7985 8032 +47
- Misses 589 593 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
maleadt
force-pushed
the
tb/checked-srem
branch
from
November 26, 2026 10:48
dd8ef73 to
b980835
Compare
Julia's codegen branches around `srem` for every divisor of -1, so that `typemin(T) % -1` returns 0. Keeping the `srem` conditional can block CSE, hoisting, and pairing with an `sdiv` of the same operands. Only `(typemin(T), -1)` overflows, so rewrite the guard on the unoptimized IR to test for that pair; LLVM then removes it whenever either operand rules the pair out, e.g. for a zero-extended index. Julia 1.15 does this itself since JuliaLang/julia#65218 (1.15.0-DEV.1007), so the rewrite only runs on older versions. In AcceleratedKernels' merge sort, merge_tile_kernel! goes from four `rem.s64` to one (451 -> 332 SASS instructions on sm_120) and merge_pass_kernel!'s remainder pairs with its division (400 -> 305).
maleadt
force-pushed
the
tb/checked-srem
branch
from
December 2, 2026 19:55
b980835 to
d567afe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Julia defines
typemin(T) % -1 == 0, where LLVM'ssremis UB, so codegen branches around thesremfor every divisor of -1. A conditionalsremcan't be CSE'd or hoisted, and doesn't pair with adivof the same operands. Only(typemin(T), -1)overflows, though:x % -1is 0 for any otherx.This pass narrows the guard to that pair. LLVM then removes it whenever either operand rules the pair out, e.g. a zero-extended index. Julia 1.15 does the same in its own codegen since JuliaLang/julia#65218 (1.15.0-DEV.1007), so the pass only runs on older versions and can be removed once those are no longer supported.
RTX 5080, Julia 1.13, CUDA.jl main:
sort!, 2^20 Float32sort, 2d (dims=1)sort, 1drem.s64in CUDA.jl's sort kernels