Skip to content

Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust#156777

Open
sgasho wants to merge 2 commits into
rust-lang:mainfrom
sgasho:test-fix-codegen-llvm-autodiff-2
Open

Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust#156777
sgasho wants to merge 2 commits into
rust-lang:mainfrom
sgasho:test-fix-codegen-llvm-autodiff-2

Conversation

@sgasho

@sgasho sgasho commented May 20, 2026

Copy link
Copy Markdown
Contributor
  • Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust
  • Change some llvm ir check in codegen_llvm/autodiff tests

r? @ZuseZ4

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 20, 2026
@rust-cloud-vms rust-cloud-vms Bot force-pushed the test-fix-codegen-llvm-autodiff-2 branch from 64371d7 to 0da69f6 Compare June 12, 2026 14:47
@sgasho

sgasho commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

I tested this PR still works after enzyme submodule update: #157716

@ZuseZ4

ZuseZ4 commented Jun 15, 2026

Copy link
Copy Markdown
Member

I think I've seen some of these changes before, so my concern is that either we continue to make the tests increasingly weaker, or we'll keep swapping back and forth between different outputs.
In the past, I added the noPostOpt flag, which made it a little better, but since the output still changed, we should find a more robust solution before putting it in CI.
Can you have a look at the -C passes=val -- a list of extra LLVM passes to run (space separated) flag, as well as some of the enzyme tests which run extra opts after enzyme?
https://github.com/EnzymeAD/Enzyme/blob/c96508349d9f121957292308c646b4a1fd53c507/enzyme/test/Enzyme/ReverseMode/add.ll#L2

We probably want to remove -Zautodiff=NoPostopt and replace it with -Zautodiff=Passes=... or something like that.
There is a -Zoffload=Host=path flag, which is also nested as an example.
The idea is that not setting the flag would result in the current behavior (full O3 after Enzyme), setting it to "" would be equal to the current NoPostOpt flag (which can then be removed) and by setting anything else we can specify the actual passes to run, similar to Enzyme.

@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jun 20, 2026
@sgasho sgasho changed the title Fix LLVM IR expectations for the autodiff abi_handling tests Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust Jun 20, 2026
@sgasho sgasho force-pushed the test-fix-codegen-llvm-autodiff-2 branch from 04bcb8e to 08f1ff1 Compare June 20, 2026 11:43
@sgasho

sgasho commented Jun 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!
I added the autodiff_post_passes flag. I thought it would be convenient to pass LLVM passes in the same format LLVM expects, comma separated. If we add a nested option like -Zautodiff=Passes=..., we would need special parsing or escaping, since -Zautodiff options are also separated by commas.

Comment thread tests/codegen-llvm/autodiff/batched.rs Outdated
Comment thread compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp Outdated
@sgasho sgasho force-pushed the test-fix-codegen-llvm-autodiff-2 branch from a7089cb to bd0eab1 Compare June 29, 2026 12:26
@rustbot

rustbot commented Jun 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.

@sgasho sgasho requested a review from ZuseZ4 June 29, 2026 13:44
@ZuseZ4

ZuseZ4 commented Jul 2, 2026

Copy link
Copy Markdown
Member

lgtm, but can you clean up the story a bit? Maybe make one commit first to introduce the infra, and then another one to update the test.
@bors delegate
with updated history and when ci is green.

@rust-bors

rust-bors Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

✌️ @sgasho, you can now approve this pull request!

If @ZuseZ4 told you to "r=me" after making some further change, then please make that change and post @bors r=ZuseZ4.

View changes since this delegation.

@sgasho sgasho force-pushed the test-fix-codegen-llvm-autodiff-2 branch from 85ca87b to 2a9e45d Compare July 2, 2026 15:45
@sgasho

sgasho commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@bors r=ZuseZ4

@rust-bors

rust-bors Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2a9e45d has been approved by ZuseZ4

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 10. This pull request will be tested once the tree is reopened.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 3, 2026
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 3, 2026
…iff-2, r=ZuseZ4

Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust

* Add -Zautodiff_post_passes flag to limit which llvm passes to run after enzyme to make autodiff tests more robust
* Change some llvm ir check in codegen_llvm/autodiff tests

r? @ZuseZ4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants