1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 #![crate_type = "lib"]
15 // verify that LLVM recognizes a loop involving 0..=n and will const-fold it.
17 //------------------------------------------------------------------------------
18 // Example from original issue #45222
20 fn foo2(n: u64) -> u64 {
23 for j in (0..=n).rev() {
30 // CHECK-LABEL: @check_foo2
32 pub fn check_foo2() -> u64 {
33 // CHECK: ret i64 500005000000000
37 //------------------------------------------------------------------------------
38 // Simplified example of #45222
40 fn triangle_inc(n: u64) -> u64 {
48 // CHECK-LABEL: @check_triangle_inc
50 pub fn check_triangle_inc() -> u64 {
51 // CHECK: ret i64 5000050000
55 //------------------------------------------------------------------------------
58 fn foo3r(n: u64) -> u64 {
61 (0 ..= n).rev().for_each(|j| {
68 // CHECK-LABEL: @check_foo3r
70 pub fn check_foo3r() -> u64 {
71 // CHECK: ret i64 500050000000