1; RUN: opt < %s -passes=gvn-sink,simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s 2 3declare i8 @ext(i1) 4 5define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext) { 6entry: 7 %cmp = icmp uge i32 %blksA, %nblks 8 br i1 %flag, label %if.then, label %if.else 9 10; CHECK-LABEL: test1 11; CHECK: call i8 @ext 12; CHECK: call i8 %ext 13if.then: 14 %frombool1 = call i8 @ext(i1 %cmp) 15 br label %if.end 16 17if.else: 18 %frombool3 = call i8 %ext(i1 %cmp) 19 br label %if.end 20 21if.end: 22 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 23 %tobool4 = icmp ne i8 %obeys.0, 0 24 ret i1 %tobool4 25} 26 27define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext) { 28entry: 29 %cmp = icmp uge i32 %blksA, %nblks 30 br i1 %flag, label %if.then, label %if.else 31 32; CHECK-LABEL: test2 33; CHECK: call i8 %ext 34; CHECK-NOT: call 35if.then: 36 %frombool1 = call i8 %ext(i1 %cmp) 37 br label %if.end 38 39if.else: 40 %frombool3 = call i8 %ext(i1 %cmp) 41 br label %if.end 42 43if.end: 44 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 45 %tobool4 = icmp ne i8 %obeys.0, 0 46 ret i1 %tobool4 47} 48 49define zeroext i1 @test3(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext1, ptr %ext2) { 50entry: 51 %cmp = icmp uge i32 %blksA, %nblks 52 br i1 %flag, label %if.then, label %if.else 53 54; CHECK-LABEL: test3 55; CHECK: %[[x:.*]] = select i1 %flag, ptr %ext1, ptr %ext2 56; CHECK: call i8 %[[x]](i1 %cmp) 57; CHECK-NOT: call 58if.then: 59 %frombool1 = call i8 %ext1(i1 %cmp) 60 br label %if.end 61 62if.else: 63 %frombool3 = call i8 %ext2(i1 %cmp) 64 br label %if.end 65 66if.end: 67 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 68 %tobool4 = icmp ne i8 %obeys.0, 0 69 ret i1 %tobool4 70} 71 72; Make sure no indirect call is introduced from direct calls 73declare i8 @ext2(i1) 74define zeroext i1 @test4(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) { 75entry: 76 %cmp = icmp uge i32 %blksA, %nblks 77 br i1 %flag, label %if.then, label %if.else 78 79; CHECK-LABEL: test4 80; CHECK: call i8 @ext( 81; CHECK: call i8 @ext2( 82if.then: 83 %frombool1 = call i8 @ext(i1 %cmp) 84 br label %if.end 85 86if.else: 87 %frombool3 = call i8 @ext2(i1 %cmp) 88 br label %if.end 89 90if.end: 91 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ] 92 %tobool4 = icmp ne i8 %obeys.0, 0 93 ret i1 %tobool4 94} 95