Skip to content

[IVDescriptors] Allow non-compare conditions in any-of selects - #69

Merged
vchuravy merged 1 commit into
JuliaLang:julia-release/23.xfrom
gbaraldi:gb/julia-23.x-anyof-non-cmp
Nov 25, 2026
Merged

vchuravy merged 1 commit into
JuliaLang:julia-release/23.xfrom
gbaraldi:gb/julia-23.x-anyof-non-cmp

Conversation

@gbaraldi

Copy link
Copy Markdown
Member

Backport of llvm#236420 (approved upstream, not merged yet) to fix the LLVM 23 regression in JuliaLang/julia#64384, where a loop that updates a Bool flag is no longer vectorized and got 8-15x slower.

isAnyOfPattern only matched select(cmp, phi, inv). InstCombine now turns zext(and(trunc nuw %flag, %c)) into select(%c, %flag, 0), so flag &= (x >= a) & (x <= b) becomes select(and(cmp, cmp), %flag, 0), which wasn't recognized. The condition can now be any i1 value that isn't part of the reduction chain (a compare may be).

The source change is the upstream diff at e9f493f and applied cleanly. The test CHECK lines are regenerated for this branch. LoopVectorize, PhaseOrdering and Analysis/IVDescriptors tests pass locally (X86, AArch64 and RISC-V targets).

Written with Claude Code (Opus 5.5 and Fable 5.2).

🤖 Generated with Claude Code

https://claude.ai/code/session_0192DBXQbMUb37k8Zk11Hk19

…236420)

`isAnyOfPattern` only matched `select(cmp, phi, inv)`. Since llvm#204927,
InstCombine turns `zext(and(trunc nuw %flag, %c))` into
`select(%c, %flag, 0)`. A bool flag kept as i8 and updated with
`flag &= (x >= a) & (x <= b)` then becomes
`select(and(cmp, cmp), %flag, 0)`, and the loop is no longer vectorized.
LLVM 22 vectorized it as an and reduction.

The vectorizer only uses the condition as a mask, so it can be any i1
value, including one defined outside the loop. It can't be part of the
reduction chain, since the vectorizer replaces the chain and the
condition would become poison. A compare is the exception: the
vectorizer rewrites a compare of the reduction phi to compare the start
value. AddReductionVar checks this once the reduction walk is done.

Reported in JuliaLang/julia#64384, where the
loop got 8-15x slower.

Backport of llvm#236420 at e9f493f, with the test
CHECK lines regenerated for this branch.

Assisted-by: Claude Code (Opus 5.5)
Assisted-by: Claude Code (Fable 5.2)
@vchuravy
vchuravy merged commit 995dc7f into JuliaLang:julia-release/23.x Nov 25, 2026
5 checks passed
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.

2 participants