MerlinVR / UdonSharp

An experimental compiler for compiling C# to Udon assembly
MIT License
678 stars 89 forks source link

Optimizations to reduce unnecessary copies #18

Closed bdunderscore closed 4 years ago

bdunderscore commented 4 years ago

This change introduces two related optimization to reduce unnecessary copies:

As part of this, we also fix some issues where function call parameters or array expressions would not respect proper order of operations.

Fixes: #15

bdunderscore commented 4 years ago

Note to self: Before merging, I need to audit to make sure that in cases where (implicit) type conversion is required, we don't attempt to use the same heap variable for the pre-conversion type, to avoid unnecessary extra heap allocations.

bdunderscore commented 4 years ago

Verified that casts work as intended, should be ready for review now.

MerlinVR commented 4 years ago

👍 will do, thanks!

bdunderscore commented 4 years ago

Found a bug in array indexing that could result in unnecessary copies, will add some more commits to fix shortly.

bdunderscore commented 4 years ago

Regression:

uint x;
x <<= 1;

seems to fail to compile now. Will update later tonight.

bdunderscore commented 4 years ago

@Merlin-san I've backed out the const conversion changes from this branch. It's looking like the const conversion stuff will be more complicated than I thought, requiring interactions with function call inference, so it's probably best to leave it until there's an IR as you suggested.