Mati365/ts-c-compiler

Detect unecessary loads

Closed this issue · 1 comments


  struct Vec2 sum(int a, int b) {
    struct Vec2 out = { .x = a + b, .y = a - b };
    return out;
  }

  void main() {
    sum(2, 3);
  }```
  
# --- Block sum ---
def sum(x{0}: int*2B, y{0}: int*2B): [ret: int2B]
  d{0}: int*2B = alloca int2B
  %t{0}: int2B = load x{0}: int*2B
  %t{1}: int2B = load y{0}: int*2B
  %t{2}: int2B = %t{0}: int2B plus %t{1}: int2B
  *(d{0}: int*2B) = store %t{2}: int2B
  %t{3}: int2B = load d{0}: int*2B
  ret %t{3}: int2B


# --- Block main ---
def main():
  %t{4}: sum*2B = offset sum
  %t{5}: int2B = call %t{4}: sum*2B :: (%1: int2B, %2: int2B)
  ret
  int sum(int x, int y) {
    int d = x + y;
    return d;
  }

  void main() {
    sum(1, 2);
  }