Skip to content

Remove unused results in DAE2#8903

Open
tlively wants to merge 1 commit into
mainfrom
dae2-results
Open

Remove unused results in DAE2#8903
tlively wants to merge 1 commit into
mainfrom
dae2-results

Conversation

@tlively

@tlively tlively commented Jul 14, 2026

Copy link
Copy Markdown
Member

Extend DeadArgumentElimination2.cpp to track and eliminate unused function return values in addition to dead parameters.

Generalize the analysis graph by introducing a unified Location variant that handles both parameter and result locations across functions and function type trees (FuncResultLoc and TypeResultLoc). Extend value-flow tracking to follow return values flowing into function returns, including tracking tail calls (tailCallees and tailCalleeTypes) so that result usage constraints propagate correctly from callees to tail-callers.

Update the fixed-point solver to propagate result usage bidirectionally across function implementations and type trees. When a function or type result is determined to be unused, update its signature result to Type::none during type rewriting and strip the return expressions and call site result types during optimization.

Extend DeadArgumentElimination2.cpp to track and eliminate unused function return values in addition to dead parameters.

Generalize the analysis graph by introducing a unified `Location` variant that handles both parameter and result locations across functions and function type trees (`FuncResultLoc` and `TypeResultLoc`). Extend value-flow tracking to follow return values flowing into function returns, including tracking tail calls (`tailCallees` and `tailCalleeTypes`) so that result usage constraints propagate correctly from callees to tail-callers.

Update the fixed-point solver to propagate result usage bidirectionally across function implementations and type trees. When a function or type result is determined to be unused, update its signature result to `Type::none` during type rewriting and strip the return expressions and call site result types during optimization.
@tlively tlively requested a review from a team as a code owner July 14, 2026 15:15
@tlively tlively requested review from aheejin and kripken and removed request for a team July 14, 2026 15:15
// Function index and parameter index.
using FuncParamLoc = std::pair<Index, Index>;

// Function index identifying the function' result (we treat result tuples as a

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Function index identifying the function' result (we treat result tuples as a
// Function index identifying the function's result (we treat result tuples as a

Also, how does an Index identify a result? Is this just the arity? Or is this mapping types to an Index in some manner?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading above, I see parameters are also mapped to an Index, but I don't remember how that works. Might be worth a general comment here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index is the index of the function whose result is being identified. That's the same as the first Index in FuncParamLoc, but we don't need a second index because there is at most one result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, the comment already says "function index" in both locations 😆

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did miss "function index" here, but the comment above says just "parameter index". Or, more fully, it says "Function index and parameter index". What is the "parameter index"? (it can't be equal to the function index, can it..?)

And, if we use a function index to identify a function's result, why not just call it a function index? Something in the design here seems confusing to me - I'm probably not remembering something basic, but I think that might be a good reason to explain the design more in a comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if "param index" means "the index in the list of parameters", then does "result loc" mean the same?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(That is, maybe Index/Loc is part of my confusion here.)

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.

2 participants