Skip to content

assert_instr: add support for stricter tests - #2212

Merged
sayantn merged 4 commits into
rust-lang:mainfrom
RalfJung:assert_instr_not
Nov 1, 2026
Merged

sayantn merged 4 commits into
rust-lang:mainfrom
RalfJung:assert_instr_not

Conversation

@RalfJung

@RalfJung RalfJung commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

Motivated by #2208, this extends assert_instr with support for stricter tests:

  • The first commit adds clauses of the form not(instr); the macro will then ensure that the given instruction does not appear in the disassembly.
  • The second commit adds clauses of the form limit(n); the macro will ensure that overall there are no more than n instructions in the disassembly.

I verified that the problematic pack tests indeed fail before the revert of #2033.

limit seems most valuable among the two since in the past apparently the global limit was raised each time some instruction just had too much boilerplate around it, so now we allow way too much slack for most instructions. With limit we could have a lower global limit and then just selectively increase the limit for the intrinsics that need it.

r? @folkertdev

@RalfJung RalfJung changed the title assert_instr: add support for explicit exclusion of bad instructions assert_instr: add support for stricter tests Aug 19, 2026
@RalfJung

Copy link
Copy Markdown
Member Author

I am also confused by ci/run.sh... it seems to never even run the AVX(2) tests with assert_instr turned on...?

@RalfJung
RalfJung force-pushed the assert_instr_not branch 2 times, most recently from 53f3cf0 to 7e05b7e Compare August 19, 2026 21:17
@rustbot

This comment has been minimized.

@RalfJung
RalfJung force-pushed the assert_instr_not branch 2 times, most recently from e55b6c8 to 373a0de Compare August 19, 2026 21:41
@RalfJung

Copy link
Copy Markdown
Member Author

Ah... it's 5 instructions somewhere. That's annoying.

disassembly for stdarch_test_shim__mm256_packs_epi16_vpacksswb: 
	 0: pushq %rbp
	 1: movq %rsp, %rbp
	 2: vpacksswb %ymm1, %ymm0, %ymm0
	 3: popq %rbp
	 4: retq

Maybe it should ignore some of these as they have nothing to do with the actual intrinsic?

@RalfJung
RalfJung force-pushed the assert_instr_not branch 2 times, most recently from 993c8d9 to 38a6da0 Compare August 20, 2026 06:16
@sayantn

sayantn commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

ci/run.sh runs the instruction assertions with only SSE2 enabled, because otherwise sometimes LLVM generates different assembly (e.g. if AVX is enabled, some SSE intrinsics will generate AVX instructions instead)

@RalfJung

Copy link
Copy Markdown
Member Author

Yeah at some point I realized that this is about which instructions are enabled statically, but it'll still actually generate code for all intrinsics and even run assert_instr for all of them, even the ones my CPU could not execute.

@rustbot

This comment has been minimized.

@RalfJung
RalfJung force-pushed the assert_instr_not branch 2 times, most recently from e0c49be to 20d179b Compare September 5, 2026 17:45
@rustbot

rustbot commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@RalfJung

Copy link
Copy Markdown
Member Author

Looks like CI is also green here now. :)
@folkertdev @Amanieu do you think these extensions to the test macro make sense?

@sayantn

sayantn commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

While we're doing this, can we also allow for testing multiple instructions as OR - will probably be useful in those weird cases when linux and windows differ etc

@RalfJung

RalfJung commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

That's definitely possible but doesn't have to happen all at once.

I don't plan to add further features to this PR, but I'm of course happy to update the existing code based on review feedback.

@sayantn

sayantn commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

sure, this lgtm. we can add more extensions later if needed

@sayantn
sayantn added this pull request to the merge queue Nov 1, 2026
Merged via the queue into rust-lang:main with commit f0733e4 Nov 1, 2026
87 checks passed
@RalfJung
RalfJung deleted the assert_instr_not branch November 15, 2026 15:32
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.

4 participants