Skip to content

Conversation

@huntergr-arm
Copy link
Contributor

Benchmarks with vs. without autovec for a loop containing conditional
scalar assignment (plus a little extra arithmetic as a 'work payload').

…ovec

Benchmarks with vs. without autovec for a loop containing conditional
scalar assignment (plus a little extra arithmetic as a 'work payload').
@huntergr-arm
Copy link
Contributor Author

Microbenchmark for FindLast/CSA autovec, as requested on llvm/llvm-project#158088

With just the conditional assignment in the loop, there was no noticeable performance difference. However, when I added a small arithmetic payload I saw a noticeable difference, especially for uint8t.

Copy link
Member

@MacDue MacDue left a comment

Choose a reason for hiding this comment

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

Generally seems reasonable to me (bar a few nits), but I've not added a benchmark before, so wait and see if there's any more comments.

@@ -0,0 +1,118 @@
#include <iostream>
Copy link
Member

@MacDue MacDue Nov 13, 2025

Choose a reason for hiding this comment

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

Was going to comment about the license header, but it seems that's not done here (looking at other files).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I wondered about that too.

// for 'A' in init_data below.
T Result = 101;
for (unsigned i = 0; i < ITERATIONS; i++) {
// Do some work to make the difference noticeable
Copy link
Contributor

Choose a reason for hiding this comment

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

could you add a few more variations, like the minimal case with just a CAS and multiple independent CAS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}
}

// Add add auto-vectorized and disabled vectorization benchmarks for math
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment needs updating, currently passes only ty and Threshold, but it might be helpful to also pass a function if it helps to reduce the duplication for additional patterns

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@huntergr-arm huntergr-arm merged commit e810d81 into llvm:main Nov 20, 2025
1 check passed
#endif

for (auto _ : state) {
VecFn(&A[0], &B[0], &C[0], Threshold);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this is working as expected. I think we need something like below to make sure the CAS result is used:

-    NoVecFn(&A[0], &B[0], &C[0], Threshold);
+    auto Res = NoVecFn(&A[0], &B[0], &C[0], Threshold);
+    benchmark::DoNotOptimize(Res);

Without a use of the result, compiler is probably able completely remove the variantst that don't have stores in the loop and also remove the unused CAS chain after inlining?

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.

3 participants