Skip to content

[UnitTests/Vectorizer] Add unit tests for find_first_of pattern#333

Open
hazzlim wants to merge 2 commits intollvm:mainfrom
hazzlim:find-first-of-test
Open

[UnitTests/Vectorizer] Add unit tests for find_first_of pattern#333
hazzlim wants to merge 2 commits intollvm:mainfrom
hazzlim:find-first-of-test

Conversation

@hazzlim
Copy link

@hazzlim hazzlim commented Feb 3, 2026

This patch adds runtime test cases for vectorization of the find_first_of idiom:

for (; first != last; ++first)
for (s_it = s_first; s_it != s_last; ++s_it)
if (*first == *s_it)
return first;
return last;

NOTE: this idiom is currently only vectorized by LoopIdiomVectorize, which is not affected by #pragma clang loop vectorize(enable).

This patch adds runtime test cases for vectorization of the
find_first_of idiom:

  for (; first != last; ++first)
    for (s_it = s_first; s_it != s_last; ++s_it)
      if (*first == *s_it)
        return first;
  return last;

NOTE: this idiom is currently only vectorized by LoopIdiomVectorize,
which is not affected by `#pragma clang loop vectorize(enable)`.
@hazzlim hazzlim requested review from david-arm and fhahn February 3, 2026 09:45
Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: this idiom is currently only vectorized by LoopIdiomVectorize, which is not affected by #pragma clang loop vectorize(enable).

So doe sthat mean that the current version does not generating a scalar version for ScalarFn?

@hazzlim
Copy link
Author

hazzlim commented Feb 9, 2026

NOTE: this idiom is currently only vectorized by LoopIdiomVectorize, which is not affected by #pragma clang loop vectorize(enable).

So doe sthat mean that the current version does not generating a scalar version for ScalarFn?

Yes that is correct - when compiling for AArch64 with +sve2 the ScalarFn will still be vectorized with the MATCH idiom by LoopIdiomVectorizePass.

There was a bit of discussion here - llvm/llvm-project#179187 (comment) - I'm not sure there's a good way to make the ScalarFn not vectorize via a source-level attribute besides __attribute__((optnone)).

From https://clang.llvm.org/docs/LanguageExtensions.html#extensions-for-loop-hint-optimizations it doesn't seem obvious to me that the vectorize(enable/disable) pragma is intended/defined to only affect the LoopVectorizer... I don't know if it would be correct/acceptable/reasonable to make it also switch LoopIdiomVectorizePass off when vectorize(disable)?

@fhahn
Copy link
Contributor

fhahn commented Feb 11, 2026

I think it would make sense for the pragma to apply there as well.

@hazzlim
Copy link
Author

hazzlim commented Feb 11, 2026

I think it would make sense for the pragma to apply there as well.

Agreed - I can look into this and open a PR

@hazzlim
Copy link
Author

hazzlim commented Feb 12, 2026

I think it would make sense for the pragma to apply there as well.

I have added llvm/llvm-project#181142.

Also updated this PR to put pragmas on the outer loop, as this makes more sense given that it is the entire nested loop which the vectorization applies to.

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