Skip to content

[UnitTests] Add initial set of tests with multiple early exits.#325

Merged
fhahn merged 2 commits into
llvm:mainfrom
fhahn:multiple-early-exit-tests
Feb 4, 2026
Merged

[UnitTests] Add initial set of tests with multiple early exits.#325
fhahn merged 2 commits into
llvm:mainfrom
fhahn:multiple-early-exit-tests

Conversation

@fhahn

@fhahn fhahn commented Jan 19, 2026

Copy link
Copy Markdown
Contributor

Extend the single-early exits tests (#264) to also test loops with multiple exits.

Depends on #264 (included in PR)

@Meinersbur

Meinersbur commented Jan 19, 2026

Copy link
Copy Markdown
Member

I took the initiative to approve #264 even though I am not in the reviewer list since none of the revierer's remarks seem to have been resolved. It will be much easier to review this one when I can see the actual diff.

@fhahn fhahn force-pushed the multiple-early-exit-tests branch from 93608f8 to 5bb9dbc Compare January 20, 2026 11:34

@fhahn fhahn left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased and simplified a bit

Comment on lines +277 to +282
, A, B, C, for (unsigned I = 0; I < N; I++) {
if (A[I] == 0)
return I;
if (A[I] == B[I])
return I + 1000;
} return -1;);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
, A, B, C, for (unsigned I = 0; I < N; I++) {
if (A[I] == 0)
return I;
if (A[I] == B[I])
return I + 1000;
} return -1;);
, A, B, C, { for (unsigned I = 0; I < N; I++) {
if (A[I] == 0)
return I;
if (A[I] == B[I])
return I + 1000;
} return -1;});

braces may help clang-format to format this better as code:

DEFINE_SCALAR_AND_VECTOR_EARLY_EXIT_2(int A[N]; int B[N]; int C[N];, A, B, C, {
  for (unsigned I = 0; I < N; I++) {
    if (A[I] == 0)
      return I;
    if (A[I] == B[I])
      return I + 1000;
  }
  return -1;
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the for loop must be directly passed, otherwise the loop pragmas cannot be applied.

#include <stdint.h>

#define N 512
// N_ODD is not divisible by common VFs (4, 8, 16) to test scalar epilogue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// N_ODD is not divisible by common VFs (4, 8, 16) to test scalar epilogue.
/// N_ODD is not divisible by common VFs (4, 8, 16) to test scalar epilogue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added thanks

Comment on lines +8 to +9
// N_SMALL is a small trip count divisible by common VFs, allowing the compiler
// to potentially eliminate the scalar remainder loop entirely.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// N_SMALL is a small trip count divisible by common VFs, allowing the compiler
// to potentially eliminate the scalar remainder loop entirely.
/// N_SMALL is a small trip count divisible by common VFs, allowing the compiler
/// to potentially eliminate the scalar remainder loop entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added thanks

#include <limits>
#include <stdint.h>

#define N 512

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It it is worth extracting out the constant, also give it a description of where it is used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added thanks

@fhahn fhahn force-pushed the multiple-early-exit-tests branch from 5bb9dbc to 8babfa6 Compare January 30, 2026 12:04

@Meinersbur Meinersbur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@fhahn fhahn merged commit f9e3b74 into llvm:main Feb 4, 2026
1 check passed
@fhahn fhahn deleted the multiple-early-exit-tests branch February 7, 2026 14:12
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