Skip to content

Commit 5203642

Browse files
committed
add codegen test for issue 73825
1 parent 023838f commit 5203642

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// issue: <https://github.com/rust-lang/rust/issues/73825>
2+
//@ compile-flags: -C opt-level=1
3+
#![crate_type = "lib"]
4+
5+
// CHECK-LABEL: @foo
6+
// CHECK-NEXT: start:
7+
// CHECK-NEXT: %_3 = and i64 %x, 63
8+
// CHECK-NEXT: %0 = getelementptr inbounds [64 x i32], ptr @0, i64 0, i64 %_3
9+
// CHECK-NEXT: %_0 = load i32, ptr %0, align 4
10+
// CHECK-NEXT: ret i32 %_0
11+
#[no_mangle]
12+
#[rustfmt::skip]
13+
pub fn foo(x: usize) -> i32 {
14+
let base: [i32; 64] = [
15+
67, 754, 860, 559, 368, 870, 548, 972,
16+
141, 731, 351, 664, 32, 4, 996, 741,
17+
203, 292, 237, 480, 151, 940, 777, 540,
18+
143, 587, 747, 65, 152, 517, 882, 880,
19+
712, 595, 370, 901, 237, 53, 789, 785,
20+
912, 650, 896, 367, 316, 392, 62, 473,
21+
675, 691, 281, 192, 445, 970, 225, 425,
22+
628, 324, 322, 206, 912, 867, 462, 92
23+
];
24+
base[x % 64]
25+
}
26+
27+
// This checks whether LLVM de-duplicates `promoted` array and `base` array.
28+
// Because in MIR, `&[..]` is already promoted by promote pass. GVN keeps promoting
29+
// `*&[..]` to `const [..]` again.
30+
//
31+
// CHECK-LABEL: @deduplicability
32+
// CHECK-NEXT: start:
33+
// CHECK-NEXT: %_3 = and i64 %x, 63
34+
// CHECK-NEXT: %0 = getelementptr inbounds [64 x i32], ptr @0, i64 0, i64 %_3
35+
// CHECK-NEXT: %_0 = load i32, ptr %0, align 4
36+
// CHECK-NEXT: ret i32 %_0
37+
#[no_mangle]
38+
#[rustfmt::skip]
39+
pub fn deduplicability(x: usize) -> i32 {
40+
let promoted = *&[
41+
67i32, 754, 860, 559, 368, 870, 548, 972,
42+
141, 731, 351, 664, 32, 4, 996, 741,
43+
203, 292, 237, 480, 151, 940, 777, 540,
44+
143, 587, 747, 65, 152, 517, 882, 880,
45+
712, 595, 370, 901, 237, 53, 789, 785,
46+
912, 650, 896, 367, 316, 392, 62, 473,
47+
675, 691, 281, 192, 445, 970, 225, 425,
48+
628, 324, 322, 206, 912, 867, 462, 92
49+
];
50+
promoted[x % 64]
51+
}

0 commit comments

Comments
 (0)