]> git.lizzy.rs Git - rust.git/blob - tests/codegen/optimize-attr-1.rs
Rollup merge of #107731 - RalfJung:interpret-discriminant, r=cjgillot
[rust.git] / tests / codegen / optimize-attr-1.rs
1 // revisions: NO-OPT SIZE-OPT SPEED-OPT
2 //[NO-OPT] compile-flags: -Copt-level=0 -Ccodegen-units=1
3 //[SIZE-OPT] compile-flags: -Copt-level=s -Ccodegen-units=1
4 //[SPEED-OPT] compile-flags: -Copt-level=3 -Ccodegen-units=1
5
6 #![feature(optimize_attribute)]
7 #![crate_type="rlib"]
8
9 // CHECK-LABEL: define{{.*}}i32 @nothing
10 // CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
11 // NO-OPT: ret i32 4
12 // SIZE-OPT: ret i32 4
13 // SPEEC-OPT: ret i32 4
14 #[no_mangle]
15 pub fn nothing() -> i32 {
16     2 + 2
17 }
18
19 // CHECK-LABEL: define{{.*}}i32 @size
20 // CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
21 // NO-OPT: ret i32 6
22 // SIZE-OPT: ret i32 6
23 // SPEED-OPT: ret i32 6
24 #[optimize(size)]
25 #[no_mangle]
26 pub fn size() -> i32 {
27     3 + 3
28 }
29
30 // CHECK-LABEL: define{{.*}}i32 @speed
31 // NO-OPT-SAME: [[NOTHING_ATTRS]]
32 // SPEED-OPT-SAME: [[NOTHING_ATTRS]]
33 // SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
34 // NO-OPT: ret i32 8
35 // SIZE-OPT: ret i32 8
36 // SPEED-OPT: ret i32 8
37 #[optimize(speed)]
38 #[no_mangle]
39 pub fn speed() -> i32 {
40     4 + 4
41 }
42
43 // NO-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
44 // SPEED-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
45 // SIZE-OPT-DAG: attributes [[NOTHING_ATTRS]] = {{.*}}optsize{{.*}}
46 // SIZE-OPT-DAG: attributes [[SIZE_ATTRS]] = {{.*}}minsize{{.*}}optsize{{.*}}
47
48 // SIZE-OPT: attributes [[SPEED_ATTRS]]
49 // SIZE-OPT-NOT: minsize
50 // SIZE-OPT-NOT: optsize