[LLVMdev] C as used/implemented in practice: analysis of responses (original) (raw)

Antoine Pitrou antoine at python.org
Mon Jul 13 11:28:21 PDT 2015


Chris Lattner <clattner apple.com> writes:

There are many more modern and much safer languages that either eliminate the UB entirely through language design (e.g. using a garbage collector to eliminate an entire class of memory safety issues, completely disallowing pointer casts to enable TBAA safely, etc), or by intentionally spending a bit of performance to provide a safe and correct programming model (e.g. by guaranteeing that integers will trap if they overflow).

For the record, in Numba when we enabled the "nsw" flag on all arithmetic operations, we got a sizable speedup (up to 2x IIRC) on some benchmarks. That's even though we implement a high-level language (Python).

For those curious, the explanation is that negative array indices are legal in Python - they mean indexing from the end of the array. So, whenever a lookup such as my_array[i+1] was used, a check was necessary to detect whether i+1 was negative even when i was known to be positive. Adding the "nsw" flag helps LLVM optimize away that check in many cases - and it turns that can enable some other optimizations such as vectorization.

Regards

Antoine.



More information about the llvm-dev mailing list