Skip to content

Interprocedural linear expression propagation#128

Merged
mira-alford merged 27 commits intomainfrom
linear-copy
Apr 22, 2026
Merged

Interprocedural linear expression propagation#128
mira-alford merged 27 commits intomainfrom
linear-copy

Conversation

@b-paul
Copy link
Copy Markdown
Collaborator

@b-paul b-paul commented Apr 17, 2026

This transform propagates assignments that are linear functions (a * x + b) through their uses. For example, if R31_2 := R31_1 - 0x2c0 then every use of R31_2 would be replaced by the expression R31_1 - 0x2c0 (plus transitivity).

For this transform to be a superset of copy propagation we also need to do a simultaneous copy only analysis, so that phi nodes are properly propagated into (since phis can only have variables in them, not linear expressions). Since it's a superset the old copyprop was removed.

The transform is interprocedural and super fast (700ms)!! I also added some stub stuff to make it propagate R31s on stubs properly !! (deleted abort case text) it handles exits too!!!!

Interestingly also the transform spends a lot of time doing wellformedness checks (the blank part)
image

@b-paul b-paul marked this pull request as draft April 21, 2026 00:56
@b-paul b-paul marked this pull request as ready for review April 21, 2026 04:22
Comment thread lib/transforms/linear_copy.ml Outdated

Trace_core.with_span ~__FILE__ ~__LINE__ "transform" @@ fun _ ->
Program.map_procedures
(fun pid proc -> transform_proc p (Hashtbl.find gs pid) proc)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Empty procedures like this:

proc @shadow(x:bv64,y:bv64) -> () {}
[
	block %shadow_entry [
		goto (%shadow_return);
	];
	block  %shadow_return [
		return();
	];
];

Have no internal variables and cause the hashmap lookup to crash. Should probably just skip such procedures given there is nothing to copy/transform anyway?

@mira-alford mira-alford self-requested a review April 22, 2026 00:26
Copy link
Copy Markdown
Collaborator

@mira-alford mira-alford left a comment

Choose a reason for hiding this comment

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

Aside from that crash on completely empty procedures, LGTM

@mira-alford mira-alford merged commit a7cd4ea into main Apr 22, 2026
9 checks passed
@mira-alford mira-alford deleted the linear-copy branch April 22, 2026 00:48
mira-alford pushed a commit that referenced this pull request Apr 22, 2026
* move out linear functions

* i think it works but it is slow

* probably works (not slow) (could be very wrong)

* Transform

* comment

* Better simplification

* Fix copyprop collapsing (now to do the linear version... terrifying...)

* fix linear copy propagation

* It does copy prop faithfully!

* Make copied_from not store edges (they were always id)

* cleanup

* remove old copy prop

* Interproc correctly

* Stubs

* idk

* doc

* tracing

* Bigger test

* comment

* bigger test...

* test

* push test oops

* propagate bools through call in test

* remove todo that is done

* Handle id leaves cycles correctly + exit stubs go to bottom

* skip empty procedures

---------

Co-authored-: Mira-Alford <mira.alford@proton.me>
mira-alford added a commit that referenced this pull request Apr 22, 2026
* building declarations

* Several fixes to smt + expr_smt

* cleanup

* Satisfied the ocaml formatter

* quick fix to wpdual function calls

* require `cmdliner>=2` (#132)

versions less than 2 don't have the `Cmd.make` function which we now
use.

* Interprocedural linear expression propagation (#128)

* move out linear functions

* i think it works but it is slow

* probably works (not slow) (could be very wrong)

* Transform

* comment

* Better simplification

* Fix copyprop collapsing (now to do the linear version... terrifying...)

* fix linear copy propagation

* It does copy prop faithfully!

* Make copied_from not store edges (they were always id)

* cleanup

* remove old copy prop

* Interproc correctly

* Stubs

* idk

* doc

* tracing

* Bigger test

* comment

* bigger test...

* test

* push test oops

* propagate bools through call in test

* remove todo that is done

* Handle id leaves cycles correctly + exit stubs go to bottom

* skip empty procedures

---------

Co-authored-: Mira-Alford <mira.alford@proton.me>

* removed comments as per jacksons DEMANDS

---------

Co-authored-by: Kait <39479354+katrinafyi@users.noreply.github.com>
Co-authored-by: b-paul <bpaul@bpaul.xyz>
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