1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=gvn -gvn-max-block-speculations=1 -S | FileCheck -check-prefix=PRE %s
3 ; RUN: opt < %s -passes=gvn -gvn-max-block-speculations=0 -S | FileCheck -check-prefix=CHECK %s
5 define i32 @loadpre_opportunity(ptr %arg, i1 %arg1, i1 %arg2, i1 %arg3) {
6 ; PRE-LABEL: @loadpre_opportunity(
8 ; PRE-NEXT: [[I:%.*]] = load ptr, ptr [[ARG:%.*]], align 8
9 ; PRE-NEXT: [[I6:%.*]] = call i32 @use(ptr [[I]])
10 ; PRE-NEXT: br label [[BB11:%.*]]
12 ; PRE-NEXT: [[I8:%.*]] = phi ptr [ [[I8_PRE:%.*]], [[BB17_BB7_CRIT_EDGE:%.*]] ], [ [[I81:%.*]], [[BB11]] ]
13 ; PRE-NEXT: [[I10:%.*]] = call i32 @use(ptr [[I8]])
14 ; PRE-NEXT: br label [[BB11]]
16 ; PRE-NEXT: [[I81]] = phi ptr [ [[I]], [[BB:%.*]] ], [ [[I8]], [[BB7:%.*]] ]
17 ; PRE-NEXT: [[I12:%.*]] = phi i32 [ [[I6]], [[BB]] ], [ [[I10]], [[BB7]] ]
18 ; PRE-NEXT: br i1 [[ARG1:%.*]], label [[BB7]], label [[BB13:%.*]]
20 ; PRE-NEXT: call void @somecall()
21 ; PRE-NEXT: br i1 [[ARG2:%.*]], label [[BB14:%.*]], label [[BB17:%.*]]
23 ; PRE-NEXT: br label [[BB15:%.*]]
25 ; PRE-NEXT: br i1 [[ARG3:%.*]], label [[BB16:%.*]], label [[BB15]]
27 ; PRE-NEXT: br label [[BB17]]
29 ; PRE-NEXT: [[I18:%.*]] = call i1 @cond()
30 ; PRE-NEXT: br i1 [[I18]], label [[BB17_BB7_CRIT_EDGE]], label [[BB19:%.*]]
31 ; PRE: bb17.bb7_crit_edge:
32 ; PRE-NEXT: [[I8_PRE]] = load ptr, ptr [[ARG]], align 8
33 ; PRE-NEXT: br label [[BB7]]
35 ; PRE-NEXT: ret i32 [[I12]]
37 ; CHECK-LABEL: @loadpre_opportunity(
39 ; CHECK-NEXT: [[I:%.*]] = load ptr, ptr [[ARG:%.*]], align 8
40 ; CHECK-NEXT: [[I6:%.*]] = call i32 @use(ptr [[I]])
41 ; CHECK-NEXT: br label [[BB11:%.*]]
43 ; CHECK-NEXT: [[I8:%.*]] = load ptr, ptr [[ARG]], align 8
44 ; CHECK-NEXT: [[I10:%.*]] = call i32 @use(ptr [[I8]])
45 ; CHECK-NEXT: br label [[BB11]]
47 ; CHECK-NEXT: [[I12:%.*]] = phi i32 [ [[I6]], [[BB:%.*]] ], [ [[I10]], [[BB7:%.*]] ]
48 ; CHECK-NEXT: br i1 [[ARG1:%.*]], label [[BB7]], label [[BB13:%.*]]
50 ; CHECK-NEXT: call void @somecall()
51 ; CHECK-NEXT: br i1 [[ARG2:%.*]], label [[BB14:%.*]], label [[BB17:%.*]]
53 ; CHECK-NEXT: br label [[BB15:%.*]]
55 ; CHECK-NEXT: br i1 [[ARG3:%.*]], label [[BB16:%.*]], label [[BB15]]
57 ; CHECK-NEXT: br label [[BB17]]
59 ; CHECK-NEXT: [[I18:%.*]] = call i1 @cond()
60 ; CHECK-NEXT: br i1 [[I18]], label [[BB7]], label [[BB19:%.*]]
62 ; CHECK-NEXT: ret i32 [[I12]]
65 %i = load ptr, ptr %arg, align 8
69 %i6 = call i32 @use(ptr %i)
73 %i8 = load ptr, ptr %arg, align 8
74 %i10 = call i32 @use(ptr %i8)
78 %i12 = phi i32 [ %i6, %bb5 ], [ %i10, %bb7 ]
79 br i1 %arg1, label %bb7, label %bb13
83 br i1 %arg2, label %bb14, label %bb17
89 br i1 %arg3, label %bb16, label %bb15
95 %i18 = call i1 @cond()
96 br i1 %i18, label %bb7, label %bb19
102 declare void @somecall()
103 declare i32 @use(ptr) readnone
104 declare i1 @cond() readnone