Skip to content

Fix LLVM IR expectations for the autodiff generic test - #156754

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

Fix LLVM IR expectations for the autodiff generic test#156754
sgasho wants to merge 2 commits into
rust-lang:mainfrom
sgasho:test-fix-codegen-llvm-autodiff

Conversation

@sgasho

@sgasho sgasho commented May 19, 2026

Copy link
Copy Markdown
Contributor

Relax the LLVM IR checks for d_square::<f64> so they do not depend on the exact return type or argument ABI(which I don't think are necessary to check here) of the generated @diffe_ call.

Also add checks that square::<f64> is generated, since d_square::<f64> needs the f64 monomorphization even though square::<f64> is not called directly. I thought it seems natural to check it, but let me know if we do not need it.

I tested it works on my local(aarch64 mac) and dev-desktop(x86_64 linux)

aarch64 apple x86_64 linux
スクリーンショット 2026-05-20 0 08 44 スクリーンショット 2026-05-20 0 09 19

r? @ZuseZ4

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 19, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 19, 2026
Comment thread tests/codegen-llvm/autodiff/generic.rs Outdated
// F64-NEXT: start:
// F64-NEXT: {{(tail )?}}call {{(fastcc )?}}void @diffe_{{.*}}(double {{.*}}, ptr {{.*}})
// F64-NEXT: ret void
// F64-NEXT: {{(tail )?}}call {{.*}} @diffe_{{.*}}

@sgasho sgasho May 19, 2026

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.

I'm still learning what level of detail LLVM IR checks should usually assert.

Since the exact return type and arg types of the generated @diffe_ call seem somewhat fragile here, would it be better to avoid checking them?

Is it enough for this test to only check that a diffe_ function is called?

View changes since the review

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.

@rust-cloud-vms
rust-cloud-vms Bot force-pushed the test-fix-codegen-llvm-autodiff branch from 3c06aea to fe4fd3f Compare June 12, 2026 13:42
@sgasho

sgasho commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

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

@rust-bors

rust-bors Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #158811) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

@Enselic

Enselic commented Aug 6, 2026

Copy link
Copy Markdown
Member

Hello, may I ask how to run the test? I've tried with this in bootstrap.toml:

profile = "compiler"  # Includes one of the default files in src/bootstrap/defaults
change-id = "ignore"
llvm.enzyme = true
llvm.download-ci-llvm = false
rust.verbose-tests=true

and I build like this:

./x test ./tests/codegen-llvm/autodiff/generic.rs

but I get this error:

[39/40] Linking CXX shared library Enzyme/libEnzyme-23.so
FAILED: Enzyme/libEnzyme-23.so
: && /usr/bin/c++ -fPIC -Wall -fno-rtti  -Wno-deprecated -ffunction-sections -fdata-sections -fPIC -m64 -w -Werror=implicit-fallthrough -Werror=unused-variable -Werror=dangling-else -Werror=unused-but-set-variable -Werror=return-type -Werror=nonnull -Werror=unused-result -Werror=reorder -Werror=switch -O2   -shared -Wl,-soname,libEnzyme-23.so -o Enzyme/libEnzyme-23.so Enzyme/CMakeFiles/Enzyme-23.dir/ActivityAnalysis.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/ActivityAnalysisPrinter.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/CApi.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/CacheUtility.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/CallDerivatives.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/DiffeGradientUtils.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/DifferentialUseAnalysis.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/Enzyme.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/EnzymeLogic.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/FixupJuliaCallingConvention.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/FunctionUtils.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/GradientUtils.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/InstructionBatcher.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/JLInstSimplify.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/MustExitScalarEvolution.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/PreserveNVVM.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/SimpleGVN.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TraceGenerator.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TraceInterface.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TraceUtils.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/Utils.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TypeAnalysis/TypeTree.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TypeAnalysis/TypeAnalysis.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TypeAnalysis/TypeAnalysisPrinter.cpp.o Enzyme/CMakeFiles/Enzyme-23.dir/TypeAnalysis/RustDebugInfo.cpp.o  -lLLVM && :
/usr/bin/ld: cannot find -lLLVM: No such file or directory
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

it says cannot find -lLLVM, which is strange since it just built LLVM locally.

I tested on a clean checkout of 887804d.

@ZuseZ4

ZuseZ4 commented Aug 6, 2026

Copy link
Copy Markdown
Member

https://rustc-dev-guide.rust-lang.org/autodiff/installation.html#build-instructions

I think you might be missing --enable-llvm-link-shared (or the bootstrap.toml equivalent)? We should probably give a better error for this.

@Enselic

Enselic commented Aug 8, 2026

Copy link
Copy Markdown
Member

Thanks, that worked 👍

Triage: Is this blocked from review somehow? Or haven't you just had time to review this yet?

@sgasho

sgasho commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

This PR is outdated and I forgot to close it
I updated generic.rs test in #156777

@sgasho sgasho closed this Aug 8, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants