Hacker News new | ask | show | jobs
by Ericson2314 2321 days ago
The earlier transformations are actually more impressive. Constant folding is almost always has a good RoI, so lots of compilers do it, and it's simple because, well, it's a constant there is no variables or partial eval needed. The others require lots of inlining before the final rule fires, and so are more ambitious.

Seeing what

  pub fn sum3(n: i32) -> i32 {
     (1..n).sum() + (1..2*n).sum() + (1..(n + 2)).sum()
  }
does would be more interesting to me.

Also, while all the inline is rustc, I assume the "triangle number trick" is LLVM.

1 comments

Godbolt supports Rust, and can show the LLVM IR: https://godbolt.org/z/GsccW3
A bit offtopic, I love how Godbolt grew out of C++ community to embrace as much AOT toolchains as possible, kudos to Matt and everyone involved into making it happen.