← Back to Pull requests

Accelerate mixed-signedness `BitInteger` comparisons #63309

Closed
unknown closed this pull request without merging on Sep 23, 2026 21:21 UTC
View on GitHub
unknown unknown commented on Sep 22, 2026 12:15 UTC
Author

:man: : As found by @matthias314 in #63287 <, <=, > and >= can be accelerated for combinations of BitSigned and BigUnsigned with 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 Int32 regression 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. S denotes the signed operand and U the 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

Diff: 468 lines (+351 / -117) across 5 files Reviewer: PatrickHaecker Review duration: 1986m
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
0.46
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
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
Assignees
Unassigned
Labels
risk: low confidence: 60.5% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 45.6% (MEDIUM) · Higher = larger blast radius
45.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 60.5% · Lower = rushed or shallow review
60.5%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 18% · Safe to merge
18%