4 ms·
> The infinite loop being UB was added because it prevents some important code motion optimizations Which ones? If this optimizations are so important, how co
by volta87 6y ago
> The infinite loop being UB was added because it prevents some important code motion optimizations
Which ones?
If this optimizations are so important, how come Rust was designed in such a way to make them impossible? Also, how does this fit, e.g., the benchmark game results which show that Rust is faster than C for all benchmarks considered there ?
- gpderetta 6y agoStore sinking for example, which is unsafe unless the loop is guaranteed to terminate. C does not have this guarantee (at least not in all cases). Also rust is compiled with the llvm backend, so my understanding is that in practice rust assumes that loops terminate. See: https://github.com/rust-lang/rust/issues/28728 https://github.com/rust-lang/rust/issues/28728 There are llvm directives that can be added to prevent the optimization, but they are rejected by the rust maintainers exactly because they would cause performance regressions.