Skip to content

Preserve noinline/debug callsite info when lowering Enzyme autodiff calls#2829

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-enzyme-noinline-attribute
Draft

Preserve noinline/debug callsite info when lowering Enzyme autodiff calls#2829
Copilot wants to merge 2 commits into
mainfrom
copilot/fix-enzyme-noinline-attribute

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 16, 2026

Enzyme was dropping callsite noinline metadata during lowering, which made rewritten calls inlineable and could trigger LLVM verifier failures (inlinable function call ... must have a !dbg location). This PR preserves the relevant callsite properties on replacement calls.

  • Root cause addressed

    • HandleAutoDiff created a new derivative call but did not carry forward callsite noinline.
    • __enzyme_call_inactive lowering created replacement calls without propagating debug location and noinline.
  • Code changes

    • Enzyme/Enzyme.cpp
      • In HandleAutoDiff(...), propagate Attribute::NoInline from the original call to the generated derivative call.
      • In inactive-call lowering (InactiveCalls loop), propagate both:
        • DebugLoc (setDebugLoc(CI->getDebugLoc()))
        • Attribute::NoInline (if present on the original call).
  • Regression coverage

    • test/Enzyme/ReverseMode/undefalloc.ll
      • Mark the __enzyme_autodiff callsite as noinline.
      • Assert the rewritten call to @diffef remains noinline.
CallInst *diffretc = cast<CallInst>(Builder.CreateCall(newFunc, args));
diffretc->setDebugLoc(CI->getDebugLoc());
if (CI->hasFnAttr(Attribute::NoInline))
  diffretc->addFnAttr(Attribute::NoInline);

// ...

auto Rep = B.CreateCall(FT, fn, Args);
Rep->setDebugLoc(CI->getDebugLoc());
if (CI->hasFnAttr(Attribute::NoInline))
  Rep->addFnAttr(Attribute::NoInline);

Copilot AI linked an issue May 16, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix enzyme pass dropping noinline attribute Preserve noinline/debug callsite info when lowering Enzyme autodiff calls May 16, 2026
Copilot AI requested a review from wsmoses May 16, 2026 23:43
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.

enzyme pass drops noinline attribute.

2 participants