Repository navigation
[IVDescriptors] Allow non-compare conditions in any-of selects - #69
Merged
vchuravy merged 1 commit intoNov 25, 2026
Merged
Conversation
…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)
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.
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
Boolflag is no longer vectorized and got 8-15x slower.isAnyOfPatternonly matchedselect(cmp, phi, inv). InstCombine now turnszext(and(trunc nuw %flag, %c))intoselect(%c, %flag, 0), soflag &= (x >= a) & (x <= b)becomesselect(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,PhaseOrderingandAnalysis/IVDescriptorstests 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