FractalFir / rustc_codegen_clr

This rust compiler backend(module) emmits valid CIL (.NET IR), enabling you to use Rust in .NET projects.
MIT License
1.51k stars 35 forks source link

Added BLt, BLt.Un, BGe, BGe.Un, BLe, BGe instructions and introduced some optimizations #46

Closed EinarSnorrason closed 4 months ago

EinarSnorrason commented 4 months ago

Implemented several branching instructions, added some optimizations to the BTrue and BFalse roots, and added some unit tests for these optimizations.

Unfortunately, when testing this I discovered that while the optimizations do work, they don't actually appear in the generated IL. This is because the IL is not doing this:

  ldloc.0
  ldloc.1
 clt
brfalse bb_4_0

Instead it's doing this:

  ldloc.0
  ldloc.1
 clt
stloc.2
.line 40:8 './lt.rs'
 ldloc.2
brfalse bb_4_0

So none of the optimizations I've written actually do anything at the moment 😅

Changing the optimization function to remove the unnecessary pushes and pops from the stack is a bit more invasive, so I might work on that in another PR.

Let me know if there's anything I should change or work on!

Resolves #44

Resolves #43