News for hackers. Stuff that matters.
Re:The Death of Optimizing Compilers by Animats on Saturday March 14, 2015 @02:15PM (#9203571)
"C has destroyed our ability to advance the state of the art in automatic optimization, automatic parallelization, automatic mapping of a high-level language to the machine."

She's right. As I occasionally point out on why C programs are so buggy, the three big problems in C are "how big is it", "who owns it", and "who locks it". The language doesn't help with any of those. Those problems also inhibit optimization.

One optimization that's been lost to history is optimizing subscript checking. This was done in some Pascal compilers, and about 95% of subscript checks can be optimized out. Where there's a loop involved, it's often possible to make one check at loop entry, rather than a check at every reference. Sometimes that one check can be proven true from FOR statement bounds, and can be eliminated. This is usually the case for numeric matrix work, where it really matters.

I had a talk with one of the designers of Rust about this last Wednesday. They're not optimizing subscript checks yet. They hope to do so. They're currently limited by being a front-end to LLVM, which doesn't really comprehend subscript checks. The Go compiler does some subscript check optimizations, but only on FOR statements of restricted form.

C, Go, and Rust all lack multidimensional arrays. This prevents a whole range of array-related optimizations which FORTRAN compilers have had all the way back to Backus's first FORTRAN compiler in 1956. This is part of why the supercomputer crowd still uses FORTRAN.

I was trying to push the Go crowd towards multidimensional arrays. People in love with the slicing syntax wanted to extend it to multidimensional arrays. There were long arguments over how far to take that. Should you be able to slice out an arbitrary sub-hypercube of an N-dimensional array? If you allow that, you have to have a slice representation which is general but inefficient. After much discussion, nothing happened.

Meanwhile, the number-crunching crowd is trying to compile Matlab, which has multi-dimensional arrays but not much else.

Re:The Death of Optimizing Compilers by sitkack on Saturday March 14, 2015 @03:06PM (#9203779)
So much is right, in many senses about FORTRAN and SQL. Both are expressive and have a limited enough semantics that allows them to be very aggressively optimized for the underlying hardware and data.

I have removed thousands of lines of Python by putting the entire working set into sqlite, transforming and projecting it relationally. Optimizations are orthogonal to the algorithm, mostly by adding and index, partition or view.

Halide is a very interesting piece of research that makes this decoupling of algorithms and schedules a core tenet.

http://people.csail.mit.edu/jrk/halide12/

I'd really like to see a relational set theoretic fork of Rust with some Fortran thrown in. I have no idea how they would all mix, but goal seems interesting.

Re:The Death of Optimizing Compilers by CyberDildonics on Saturday March 14, 2015 @02:42PM (#9203680)
Julia is definitely worth a look as it has taken on some of these issues (multi-dimensional arrays, slicing, some bounds checking). Now that it has a good garbage collector its remaining achilles heals are multi-threading (there are multiple processes that can send messages though) and long start up times for some modules (no JIT caching yet). It does make a lot of really good decisions at the language level though and is faster than many native languages while being more flexible than many scripting languages.
Re:The Death of Optimizing Compilers by cbsmith on Saturday March 14, 2015 @04:31PM (#9204060)
> One optimization that's been lost to history is optimizing subscript checking.

Depends upon how you look at it. Most JIT compilers do this.

Re:The Death of Optimizing Compilers by kibwen on Saturday March 14, 2015 @11:37PM (#9205273)
It's not a priority for Rust to hoist subscript checks in loops, because Rust uses iterators pervasively and iterators are guaranteed to check the bounds of the array no more than once.
Re:The Death of Optimizing Compilers by dbaupp on Sunday March 15, 2015 @08:35PM (#9208917)
LLVM (used by rustc) is perfectly capable of hoisting and eliminating subscript checks, although I believe rustc doesn't necessarily drive LLVM in the optimal way, yet: https://github.com/rust-lang/rust/issues/22987

E.g. this has no bounds checks, and is in fact vectorised:

  pub fn bad_sum(x: &[i32]) -> i32 {
      let x = x; // *
      let mut sum = 0;
      for i in 0..x.len() {
          sum += x[i]
      }
      sum
  }

The line marked * is needed because of https://github.com/rust-lang/rust/issues/22924 which is caused by https://llvm.org/bugs/show_bug.cgi?id=22786 .
Re:The Death of Optimizing Compilers by Animats on Sunday March 15, 2015 @12:35AM (#9205372)
Write a matrix multiply. Or a linear equation solver.
Re:The Death of Optimizing Compilers by pcwalton on Thursday March 19, 2015 @05:48PM (#9234825)
The bounds checks for matrix multiplication over fixed length arrays are completely optimized out by LLVM, and LLVM will also optimize the bounds checks for non-fixed-length arrays in many cases. The slice length is an SSA value, so it's subject to constant propagation and SCCP.
Re:The Death of Optimizing Compilers by Lofkin on Saturday March 14, 2015 @10:25PM (#9205104)
Julia and Python Numba are two fast (almost native) high level languages for multdimensional array programming.