1; RUN: opt -gvn-sink -S < %s | FileCheck %s
2
3%struct = type {i32, i32}
4%struct2 = type { [ 2 x i32], i32 }
5
6; Struct indices cannot be variant.
7
8; CHECK-LABEL: @f() {
9; CHECK: getelementptr
10; CHECK: getelementptr
11define void @f() {
12bb:
13  br i1 undef, label %bb2, label %bb1
14
15bb1:                                              ; preds = %bb
16  %tmp = getelementptr inbounds %struct, %struct* null, i64 0, i32 1
17  br label %bb4
18
19bb2:                                              ; preds = %bb
20  %tmp3 = getelementptr inbounds %struct, %struct* null, i64 0, i32 0
21  br label %bb4
22
23bb4:                                              ; preds = %bb2, %bb1
24  %tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
25  ret void
26}
27
28; Struct indices cannot be variant.
29
30; CHECK-LABEL: @g() {
31; CHECK: getelementptr
32; CHECK: getelementptr
33define void @g() {
34bb:
35  br i1 undef, label %bb2, label %bb1
36
37bb1:                                              ; preds = %bb
38  %tmp = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 1
39  br label %bb4
40
41bb2:                                              ; preds = %bb
42  %tmp3 = getelementptr inbounds %struct2, %struct2* null, i64 0, i32 0, i32 0
43  br label %bb4
44
45bb4:                                              ; preds = %bb2, %bb1
46  %tmp5 = phi i32 [ 1, %bb1 ], [ 0, %bb2 ]
47  ret void
48}
49
50
51; ... but the first parameter to a GEP can.
52
53; CHECK-LABEL: @h() {
54; CHECK: getelementptr
55; CHECK-NOT: getelementptr
56define void @h() {
57bb:
58  br i1 undef, label %bb2, label %bb1
59
60bb1:                                              ; preds = %bb
61  %tmp = getelementptr inbounds %struct, %struct* null, i32 0, i32 0
62  br label %bb4
63
64bb2:                                              ; preds = %bb
65  %tmp3 = getelementptr inbounds %struct, %struct* null, i32 1, i32 0
66  br label %bb4
67
68bb4:                                              ; preds = %bb2, %bb1
69  %tmp5 = phi i32 [ 0, %bb1 ], [ 1, %bb2 ]
70  ret void
71}