Accelerate mixed-signedness `BitInteger` comparisons #63309
All Vouch review confidence checks passed
Residual risk 0.18 = Change Risk (0.46) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.46 · 468 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.368
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #63309"
general
weight: 0.35
PatrickHaecker
:man: : As found by @matthias314 in #63287
<,<=,>and>=can be accelerated for combinations ofBitSignedandBigUnsignedwith different widths.It's not always a win, but nearly always and the average seems clear.
Strictly speaking, such optimizations should be done in LLVM, but LLVM does seem to lack the interface for general integer comparisons. That would allow to avoid the vectorized
Int32regression and it would allow additional optimizations, like same-width-different-signedness comparisons by upcasting both, where scalar and vectorized usage seems to need different algorithms to be most efficient.However, for the moment, it seems to be the most pragmatic approach to land this in Julia and rework it if/when LLVM should provide the necessary interface. The gains seem to be too large to be left on the table for such a basic functionality.
Big thanks to @matthias314 for finding such an impressive optimization!
----
:robot: : Compare in the signed type when it can represent every value of the unsigned type, avoiding redundant sign checks. Share comparison logic across operand orders.
Benchmarks on an Intel Core i7-1270P, pinned to a performance core, using Julia 1.14.0-DEV.3129 with LLVM 22.1.8. Both tables measure warmed 256-element arrays with Bool output. Scalar measurements disable LLVM loop and SLP vectorization. Timings exclude input generation but include loads, stores, and loop overhead.
Values are changes in execution time, rounded to whole percentages. Negative means faster.
Sdenotes the signed operand andUthe unsigned operand.Scalar Loops
| Operand types | S < U | U < S | S <= U | U <= S |
|---|---:|---:|---:|---:|
| Int16 / UInt8 | -44% | -44% | -42% | -45% |
| Int32 / UInt8 | -45% | -44% | -44% | -44% |
| Int32 / UInt16 | -45% | -43% | -43% | -43% |
| Int64 / UInt8 | -43% | -43% | -41% | -43% |
| Int64 / UInt16 | -43% | -43% | -42% | -44% |
| Int64 / UInt32 | -42% | -42% | -41% | -41% |
| Int128 / UInt8 | -32% | -34% | -34% | -25% |
| Int128 / UInt16 | -27% | -32% | -35% | -28% |
| Int128 / UInt32 | -26% | -33% | -35% | -25% |
| Int128 / UInt64 | -27% | -35% | -38% | -25% |
Vector Loops
| Operand types | S < U | U < S | S <= U | U <= S |
|---|---:|---:|---:|---:|
| Int16 / UInt8 | -10% | -2% | -2% | 0% |
| Int32 / UInt8 | 0% | +10% | +10% | +10% |
| Int32 / UInt16 | 0% | +10% | +10% | +10% |
| Int64 / UInt8 | -19% | -19% | -15% | -15% |
| Int64 / UInt16 | -19% | -19% | -15% | -15% |
| Int64 / UInt32 | -19% | -19% | -16% | -15% |
| Int128 / UInt8 | -46% | -40% | -46% | -39% |
| Int128 / UInt16 | -46% | -39% | -46% | -40% |
| Int128 / UInt32 | -48% | -41% | -48% | -41% |
| Int128 / UInt64 | -41% | -45% | -49% | -34% |
Measurements compare averages of the fastest half of 3,001 samples, with 1,000 passes per sample and both benchmark orders checked. Identical-function controls were below 1% for all retained vector cases and 32 of 40 scalar cases. The remaining eight scalar controls differed by roughly 1–6%, so the percentages should be interpreted as approximate.
The Int32 vector regressions result from LLVM choosing less efficient Boolean packing. Changing only that packing sequence removes the regression in an isolated assembly experiment. Reverting the operand-forwarding simplification produces identical vector assembly and therefore does not help.
Overall, these workloads favor the optimization, although the benefit depends on operand types and execution mode. Ultimately, target-aware comparison optimization and Boolean packing belong in LLVM.
Assisted-By: GPT-6 Astra