1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S %s | FileCheck %s
4 ; RUN: opt -passes='simplifycfg<sink-common-insts;hoist-common-insts>,verify' -S %s | FileCheck %s
6 declare void @clobber1()
7 declare void @clobber2()
9 define void @sink(ptr %arg, i1 %c) {
10 ; CHECK-LABEL: define void @sink(
11 ; CHECK-SAME: ptr [[ARG:%.*]], i1 [[C:%.*]]) {
13 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
15 ; CHECK-NEXT: call void @clobber1()
16 ; CHECK-NEXT: store ptr null, ptr [[ARG]], align 8
17 ; CHECK-NEXT: br label [[EXIT:%.*]]
19 ; CHECK-NEXT: call void @clobber2()
20 ; CHECK-NEXT: store ptr null, ptr [[ARG]], align 8, !mmra [[META0:![0-9]+]]
21 ; CHECK-NEXT: br label [[EXIT]]
23 ; CHECK-NEXT: ret void
26 br i1 %c, label %then, label %else
30 store ptr null, ptr %arg, align 8
35 store ptr null, ptr %arg, align 8, !mmra !0
42 define void @hoist_store(ptr %arg, i1 %c) {
43 ; CHECK-LABEL: define void @hoist_store(
44 ; CHECK-SAME: ptr [[ARG:%.*]], i1 [[C:%.*]]) {
46 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
48 ; CHECK-NEXT: store ptr null, ptr [[ARG]], align 8
49 ; CHECK-NEXT: call void @clobber1()
50 ; CHECK-NEXT: br label [[EXIT:%.*]]
52 ; CHECK-NEXT: store ptr null, ptr [[ARG]], align 8, !mmra [[META0]]
53 ; CHECK-NEXT: call void @clobber2()
54 ; CHECK-NEXT: br label [[EXIT]]
56 ; CHECK-NEXT: ret void
59 br i1 %c, label %then, label %else
62 store ptr null, ptr %arg, align 8
67 store ptr null, ptr %arg, align 8, !mmra !0
75 define ptr @sink_load(ptr %arg, i1 %c) {
76 ; CHECK-LABEL: define ptr @sink_load(
77 ; CHECK-SAME: ptr [[ARG:%.*]], i1 [[C:%.*]]) {
79 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
81 ; CHECK-NEXT: call void @clobber1()
82 ; CHECK-NEXT: [[L1:%.*]] = load ptr, ptr [[ARG]], align 8
83 ; CHECK-NEXT: br label [[EXIT:%.*]]
85 ; CHECK-NEXT: call void @clobber2()
86 ; CHECK-NEXT: [[L2:%.*]] = load ptr, ptr [[ARG]], align 8, !mmra [[META0]]
87 ; CHECK-NEXT: br label [[EXIT]]
89 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[L1]], [[THEN]] ], [ [[L2]], [[ELSE]] ]
90 ; CHECK-NEXT: ret ptr [[P]]
93 br i1 %c, label %then, label %else
97 %l1 = load ptr, ptr %arg, align 8
101 call void @clobber2()
102 %l2 = load ptr, ptr %arg, align 8, !mmra !0
106 %p = phi ptr [ %l1, %then ], [ %l2, %else ]
110 define ptr @hoist_load(ptr %arg, i1 %c) {
111 ; CHECK-LABEL: define ptr @hoist_load(
112 ; CHECK-SAME: ptr [[ARG:%.*]], i1 [[C:%.*]]) {
114 ; CHECK-NEXT: br i1 [[C]], label [[THEN:%.*]], label [[ELSE:%.*]]
116 ; CHECK-NEXT: [[L1:%.*]] = load ptr, ptr [[ARG]], align 8
117 ; CHECK-NEXT: call void @clobber1()
118 ; CHECK-NEXT: br label [[EXIT:%.*]]
120 ; CHECK-NEXT: [[L2:%.*]] = load ptr, ptr [[ARG]], align 8, !mmra [[META0]]
121 ; CHECK-NEXT: call void @clobber2()
122 ; CHECK-NEXT: br label [[EXIT]]
124 ; CHECK-NEXT: [[P:%.*]] = phi ptr [ [[L1]], [[THEN]] ], [ [[L2]], [[ELSE]] ]
125 ; CHECK-NEXT: ret ptr [[P]]
128 br i1 %c, label %then, label %else
131 %l1 = load ptr, ptr %arg, align 8
132 call void @clobber1()
136 %l2 = load ptr, ptr %arg, align 8, !mmra !0
137 call void @clobber2()
141 %p = phi ptr [ %l1, %then ], [ %l2, %else ]
146 !0 = !{!"foo", !"bar"}
149 ; CHECK: [[META0]] = !{!"foo", !"bar"}