ts-c-compiler icon indicating copy to clipboard operation
ts-c-compiler copied to clipboard

Detect unecessary loads

Open Mati365 opened this issue 3 years ago • 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);
  }```
  

Mati365 avatar Jun 20 '22 08:06 Mati365

# --- 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);
  }

Mati365 avatar Jun 20 '22 10:06 Mati365