EnzymeAD / EnzymeAD/Enzyme

MLIR reverse mode: cache overwritten arguments so calls to memory-writing callees can be differentiated

Open
#3,109 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
LLVM
Stars
1.7k
Forks
188
Avg merge
1d 22h
Merged PRs (30d)
26

Description

The reverse-mode call handler refuses a callee that writes memory:

```
cannot differentiate a call in reverse mode whose callee touches memory; caching of overwritten arguments is not yet implemented here
```

The refusal exists because the adjoint of a call re-runs/uses the callee's primal values in the reverse pass, and a pointer argument may have been overwritten between the original forward execution of the call and its reverse — LLVM Enzyme handles this with `overwritten_args` (caching the argument values/buffers that later writes clobber), which has no MLIR-side counterpart yet (#3079 renamed the plumbing to `overwritten_args` but the analysis and caching are not implemented).

The guard checks, transitively through direct callees: an `llvm.call`/`llvm.func` with a none `memory_effects` attr or `readnone` passthrough, or a body whose ops are all memory-effect-free. What it cannot accept is a callee that genuinely stores — `enzyme/test/MLIR/ReverseMode/func_call_write.mlir` (a callee writing through a dup memref argument) is exactly that case and is marked XFAIL until the caching lands.

@pangoraw — flagging per the split-reverse discussion: implementing overwritten-args caching on the MLIR side would re-enable that test (remove its XFAIL) and lift the refusal generally.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_016zErYp7upmqr4NHfhod9UD

Contributor guide

Open the contributing guide

Research direction

Start with the MLIR reverse-mode call handler and the overwritten_args plumbing referenced in the issue. Read enzyme/test/MLIR/ReverseMode/func_call_write.mlir and run it to understand the current XFAIL behavior. Implement the missing caching, then remove the XFAIL and verify that the test passes and memory-writing callees are accepted.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.