1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=simplifycfg -sink-common-insts -simplifycfg-require-and-preserve-domtree=1 -S < %s | FileCheck %s
4 define ptr @test_sink_gep(i1 %c, ptr %p) {
5 ; CHECK-LABEL: @test_sink_gep(
7 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 1
8 ; CHECK-NEXT: ret ptr [[GEP2]]
10 br i1 %c, label %if, label %else
13 %gep1 = getelementptr i32, ptr %p, i64 1
17 %gep2 = getelementptr i32, ptr %p, i64 1
21 %phi = phi ptr [ %gep1, %if ], [ %gep2, %else]
25 define ptr @test_sink_gep_different_types(i1 %c, ptr %p) {
26 ; CHECK-LABEL: @test_sink_gep_different_types(
28 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i32, ptr [[P:%.*]], i64 1
29 ; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i64, ptr [[P]], i64 1
30 ; CHECK-NEXT: [[PHI:%.*]] = select i1 [[C:%.*]], ptr [[GEP1]], ptr [[GEP2]]
31 ; CHECK-NEXT: ret ptr [[PHI]]
33 br i1 %c, label %if, label %else
36 %gep1 = getelementptr i32, ptr %p, i64 1
40 %gep2 = getelementptr i64, ptr %p, i64 1
44 %phi = phi ptr [ %gep1, %if ], [ %gep2, %else]
48 define void @test_cond_store_merge(i1 %arg, i1 %arg2, ptr %p) {
49 ; CHECK-LABEL: @test_cond_store_merge(
51 ; CHECK-NEXT: br i1 [[ARG:%.*]], label [[BB2:%.*]], label [[BB3:%.*]]
53 ; CHECK-NEXT: store i64 0, ptr [[P:%.*]], align 32
54 ; CHECK-NEXT: br label [[BB3]]
56 ; CHECK-NEXT: br i1 [[ARG2:%.*]], label [[BB4:%.*]], label [[BB5:%.*]]
58 ; CHECK-NEXT: store double 0.000000e+00, ptr [[P]], align 32
59 ; CHECK-NEXT: br label [[BB5]]
61 ; CHECK-NEXT: ret void
64 br i1 %arg, label %bb2, label %bb3
67 store i64 0, ptr %p, align 32
70 bb3: ; preds = %bb2, %bb
71 br i1 %arg2, label %bb4, label %bb5
74 store double 0.000000e+00, ptr %p, align 32
77 bb5: ; preds = %bb4, %bb3