Skip to content

fix: hoist alloca out of loop in custom sort comparator#292

Merged
cs01 merged 1 commit intomainfrom
fix/sort-hoist-alloca
Mar 12, 2026
Merged

fix: hoist alloca out of loop in custom sort comparator#292
cs01 merged 1 commit intomainfrom
fix/sort-hoist-alloca

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • The inner loop counter (jPtr) in generateNumericSortWithFn was allocated with alloca inside the outer loop body. Each iteration created a new stack allocation, violating LLVM's "hoist allocas to entry block" rule and risking stack overflow on large arrays.
  • Moved the alloca before the loop; the outer body now just resets it with a store.

Test plan

  • Existing sort tests pass
  • npm run verify:quick passes (tests + Stage 1 self-hosting)

@cs01 cs01 merged commit 3ad7a16 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/sort-hoist-alloca branch March 19, 2026 05:23
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