TypeAnalysis: fall back to LLVM type for extractvalue when operand has no type info#2783
Draft
TypeAnalysis: fall back to LLVM type for extractvalue when operand has no type info#2783
Conversation
… opaque calls Agent-Logs-Url: https://github.com/EnzymeAD/Enzyme/sessions/a03198dd-3b66-47e4-bb50-270043b20b6a Co-authored-by: minansys <149007967+minansys@users.noreply.github.com>
Agent-Logs-Url: https://github.com/EnzymeAD/Enzyme/sessions/a03198dd-3b66-47e4-bb50-270043b20b6a Co-authored-by: minansys <149007967+minansys@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix enzyme cannot deduce type of extract error
TypeAnalysis: fall back to LLVM type for extractvalue when operand has no type info
Apr 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an opaque function call returns a struct containing float arrays, TypeAnalysis produces
{}(unknown) for the call result. Subsequentextractvalueinstructions that extract fields from that result inherit the unknown type, causing "Cannot deduce type of extract" errors during differentiation.Root cause
visitExtractValueInstpropagates type info viaShiftIndiceson the operand's TypeTree. When the operand is{},ShiftIndicesreturns{}, leaving the extracted value with no type info — even when the LLVM IR type is unambiguous (e.g.,[2 x float]).Fix
In the DOWN direction of
visitExtractValueInst, whenShiftIndicesyields no type info, fall back todefaultTypeTreeForLLVM(I.getType(), &I, /*intIsPointer=*/false). Unlike memory loads where aliasing can create type ambiguity,extractvalueoperates on value-typed aggregates whose field types are fully determined by the IR — making the LLVM type authoritative.The fix also triggers UP-direction back-propagation, so the opaque call result itself gets float type annotations at the appropriate offsets.
Test
Added
test/TypeAnalysis/extractvalue_opaque_call.llcovering multi-levelextractvaluechains from opaque struct-returning calls.