Skip to content

feat(ssa): Deduplicate intrinsics with predicates#6615

Merged
aakoshh merged 9 commits intomasterfrom
6533-dedup-intrinsic-side-effect
Nov 27, 2024
Merged

feat(ssa): Deduplicate intrinsics with predicates#6615
aakoshh merged 9 commits intomasterfrom
6533-dedup-intrinsic-side-effect

Conversation

@aakoshh
Copy link
Contributor

@aakoshh aakoshh commented Nov 25, 2024

Description

Problem*

Resolves #6533

Summary*

Allows Instruction::Intrinsic types to be deduplicated in constant_folding if the Context is in use_constraint_info mode, and the Intrinsic is one that doesn't have a side effect other than the possibility of violating an implicit constraint on its inputs, which should be preserved in the first occurrence.

Additional Context

I found it a bit confusing why we're using use_constraint_info for these whenrequires_acir_gen_predicate returns false for all these instructions, which will cause cached_instruction_results to contain None for the predicate regardless of use_constraint_info. For some, but not all intrinsics, the predicate that tells whether the side effect is enabled is attached to their inputs during Ssa::flatten_cfg, and they don't depend any more on the enable_side_effect instruction. But it seems like this flag is the one that communicates whether we want such instructions to be deduplicated, so I used it even though I'm not sure what adverse effect we would see if we just returned true for these, other than the implicit coupling by knowing that flatten_cfg has done things in a certain way.

Another method that seems to have some of the truth is remove_enable_side_effects::Context::responds_to_side_effects_var

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Loading
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.

Deduplicate intrinsics with side effects when they're under the same predicate

4 participants