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