95 lines · plain
1; RUN: opt < %s -passes=gvn-sink,simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s2 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, %nblks8 br i1 %flag, label %if.then, label %if.else9 10; CHECK-LABEL: test111; CHECK: call i8 @ext12; CHECK: call i8 %ext13if.then:14 %frombool1 = call i8 @ext(i1 %cmp)15 br label %if.end16 17if.else:18 %frombool3 = call i8 %ext(i1 %cmp)19 br label %if.end20 21if.end:22 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]23 %tobool4 = icmp ne i8 %obeys.0, 024 ret i1 %tobool425}26 27define zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext) {28entry:29 %cmp = icmp uge i32 %blksA, %nblks30 br i1 %flag, label %if.then, label %if.else31 32; CHECK-LABEL: test233; CHECK: call i8 %ext34; CHECK-NOT: call35if.then:36 %frombool1 = call i8 %ext(i1 %cmp)37 br label %if.end38 39if.else:40 %frombool3 = call i8 %ext(i1 %cmp)41 br label %if.end42 43if.end:44 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]45 %tobool4 = icmp ne i8 %obeys.0, 046 ret i1 %tobool447}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, %nblks52 br i1 %flag, label %if.then, label %if.else53 54; CHECK-LABEL: test355; CHECK: %[[x:.*]] = select i1 %flag, ptr %ext1, ptr %ext256; CHECK: call i8 %[[x]](i1 %cmp)57; CHECK-NOT: call58if.then:59 %frombool1 = call i8 %ext1(i1 %cmp)60 br label %if.end61 62if.else:63 %frombool3 = call i8 %ext2(i1 %cmp)64 br label %if.end65 66if.end:67 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]68 %tobool4 = icmp ne i8 %obeys.0, 069 ret i1 %tobool470}71 72; Make sure no indirect call is introduced from direct calls73declare i8 @ext2(i1)74define zeroext i1 @test4(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {75entry:76 %cmp = icmp uge i32 %blksA, %nblks77 br i1 %flag, label %if.then, label %if.else78 79; CHECK-LABEL: test480; CHECK: call i8 @ext(81; CHECK: call i8 @ext2(82if.then:83 %frombool1 = call i8 @ext(i1 %cmp)84 br label %if.end85 86if.else:87 %frombool3 = call i8 @ext2(i1 %cmp)88 br label %if.end89 90if.end:91 %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]92 %tobool4 = icmp ne i8 %obeys.0, 093 ret i1 %tobool494}95