xref: /llvm-project/llvm/test/Transforms/GVNSink/indirect-call.ll (revision 055fb7795aa219a3d274d280ec9129784f169f56)
12adab06dSRoman Lebedev; RUN: opt < %s -passes=gvn-sink,simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s
2cee313d2SEric Christopher
3cee313d2SEric Christopherdeclare i8 @ext(i1)
4cee313d2SEric Christopher
5*055fb779SNikita Popovdefine zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext) {
6cee313d2SEric Christopherentry:
7cee313d2SEric Christopher  %cmp = icmp uge i32 %blksA, %nblks
8cee313d2SEric Christopher  br i1 %flag, label %if.then, label %if.else
9cee313d2SEric Christopher
10cee313d2SEric Christopher; CHECK-LABEL: test1
11cee313d2SEric Christopher; CHECK: call i8 @ext
12cee313d2SEric Christopher; CHECK: call i8 %ext
13cee313d2SEric Christopherif.then:
14cee313d2SEric Christopher  %frombool1 = call i8 @ext(i1 %cmp)
15cee313d2SEric Christopher  br label %if.end
16cee313d2SEric Christopher
17cee313d2SEric Christopherif.else:
18cee313d2SEric Christopher  %frombool3 = call i8 %ext(i1 %cmp)
19cee313d2SEric Christopher  br label %if.end
20cee313d2SEric Christopher
21cee313d2SEric Christopherif.end:
22cee313d2SEric Christopher  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
23cee313d2SEric Christopher  %tobool4 = icmp ne i8 %obeys.0, 0
24cee313d2SEric Christopher  ret i1 %tobool4
25cee313d2SEric Christopher}
26cee313d2SEric Christopher
27*055fb779SNikita Popovdefine zeroext i1 @test2(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext) {
28cee313d2SEric Christopherentry:
29cee313d2SEric Christopher  %cmp = icmp uge i32 %blksA, %nblks
30cee313d2SEric Christopher  br i1 %flag, label %if.then, label %if.else
31cee313d2SEric Christopher
32cee313d2SEric Christopher; CHECK-LABEL: test2
33cee313d2SEric Christopher; CHECK: call i8 %ext
34cee313d2SEric Christopher; CHECK-NOT: call
35cee313d2SEric Christopherif.then:
36cee313d2SEric Christopher  %frombool1 = call i8 %ext(i1 %cmp)
37cee313d2SEric Christopher  br label %if.end
38cee313d2SEric Christopher
39cee313d2SEric Christopherif.else:
40cee313d2SEric Christopher  %frombool3 = call i8 %ext(i1 %cmp)
41cee313d2SEric Christopher  br label %if.end
42cee313d2SEric Christopher
43cee313d2SEric Christopherif.end:
44cee313d2SEric Christopher  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
45cee313d2SEric Christopher  %tobool4 = icmp ne i8 %obeys.0, 0
46cee313d2SEric Christopher  ret i1 %tobool4
47cee313d2SEric Christopher}
48cee313d2SEric Christopher
49*055fb779SNikita Popovdefine zeroext i1 @test3(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks, ptr %ext1, ptr %ext2) {
50cee313d2SEric Christopherentry:
51cee313d2SEric Christopher  %cmp = icmp uge i32 %blksA, %nblks
52cee313d2SEric Christopher  br i1 %flag, label %if.then, label %if.else
53cee313d2SEric Christopher
54cee313d2SEric Christopher; CHECK-LABEL: test3
55*055fb779SNikita Popov; CHECK: %[[x:.*]] = select i1 %flag, ptr %ext1, ptr %ext2
56cee313d2SEric Christopher; CHECK: call i8 %[[x]](i1 %cmp)
57cee313d2SEric Christopher; CHECK-NOT: call
58cee313d2SEric Christopherif.then:
59cee313d2SEric Christopher  %frombool1 = call i8 %ext1(i1 %cmp)
60cee313d2SEric Christopher  br label %if.end
61cee313d2SEric Christopher
62cee313d2SEric Christopherif.else:
63cee313d2SEric Christopher  %frombool3 = call i8 %ext2(i1 %cmp)
64cee313d2SEric Christopher  br label %if.end
65cee313d2SEric Christopher
66cee313d2SEric Christopherif.end:
67cee313d2SEric Christopher  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
68cee313d2SEric Christopher  %tobool4 = icmp ne i8 %obeys.0, 0
69cee313d2SEric Christopher  ret i1 %tobool4
70cee313d2SEric Christopher}
7143d98a0eSMatt Arsenault
7243d98a0eSMatt Arsenault; Make sure no indirect call is introduced from direct calls
7343d98a0eSMatt Arsenaultdeclare i8 @ext2(i1)
7443d98a0eSMatt Arsenaultdefine zeroext i1 @test4(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
7543d98a0eSMatt Arsenaultentry:
7643d98a0eSMatt Arsenault  %cmp = icmp uge i32 %blksA, %nblks
7743d98a0eSMatt Arsenault  br i1 %flag, label %if.then, label %if.else
7843d98a0eSMatt Arsenault
7943d98a0eSMatt Arsenault; CHECK-LABEL: test4
8043d98a0eSMatt Arsenault; CHECK: call i8 @ext(
8143d98a0eSMatt Arsenault; CHECK: call i8 @ext2(
8243d98a0eSMatt Arsenaultif.then:
8343d98a0eSMatt Arsenault  %frombool1 = call i8 @ext(i1 %cmp)
8443d98a0eSMatt Arsenault  br label %if.end
8543d98a0eSMatt Arsenault
8643d98a0eSMatt Arsenaultif.else:
8743d98a0eSMatt Arsenault  %frombool3 = call i8 @ext2(i1 %cmp)
8843d98a0eSMatt Arsenault  br label %if.end
8943d98a0eSMatt Arsenault
9043d98a0eSMatt Arsenaultif.end:
9143d98a0eSMatt Arsenault  %obeys.0 = phi i8 [ %frombool1, %if.then ], [ %frombool3, %if.else ]
9243d98a0eSMatt Arsenault  %tobool4 = icmp ne i8 %obeys.0, 0
9343d98a0eSMatt Arsenault  ret i1 %tobool4
9443d98a0eSMatt Arsenault}
95