1; REQUIRES: asserts
2
3; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
4; RUN: opt < %s -instcombine --debug-counter=assume-queries-counter-skip=0,assume-queries-counter-count=1 -S | FileCheck %s --check-prefixes=COUNTER1
5; RUN: opt < %s -instcombine --debug-counter=assume-queries-counter-skip=1,assume-queries-counter-count=6 -S | FileCheck %s --check-prefixes=COUNTER2
6; RUN: opt < %s -instcombine --debug-counter=assume-queries-counter-skip=6,assume-queries-counter-count=1 -S | FileCheck %s --check-prefixes=COUNTER3
7
8declare i1 @get_val()
9declare void @llvm.assume(i1)
10
11define dso_local i1 @test1(i32* readonly %0) {
12; COUNTER1-LABEL: @test1(
13; COUNTER1-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0:%.*]]) ]
14; COUNTER1-NEXT:    ret i1 false
15;
16; COUNTER2-LABEL: @test1(
17; COUNTER2-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0:%.*]]) ]
18; COUNTER2-NEXT:    [[TMP2:%.*]] = icmp eq i32* [[TMP0]], null
19; COUNTER2-NEXT:    ret i1 [[TMP2]]
20;
21; COUNTER3-LABEL: @test1(
22; COUNTER3-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0:%.*]]) ]
23; COUNTER3-NEXT:    [[TMP2:%.*]] = icmp eq i32* [[TMP0]], null
24; COUNTER3-NEXT:    ret i1 [[TMP2]]
25;
26  call void @llvm.assume(i1 true) ["nonnull"(i32* %0)]
27  %2 = icmp eq i32* %0, null
28  ret i1 %2
29}
30
31define dso_local i1 @test2(i32* readonly %0) {
32; COUNTER1-LABEL: @test2(
33; COUNTER1-NEXT:    [[TMP2:%.*]] = icmp eq i32* [[TMP0:%.*]], null
34; COUNTER1-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0]]) ]
35; COUNTER1-NEXT:    ret i1 [[TMP2]]
36;
37; COUNTER2-LABEL: @test2(
38; COUNTER2-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0:%.*]]) ]
39; COUNTER2-NEXT:    ret i1 false
40;
41; COUNTER3-LABEL: @test2(
42; COUNTER3-NEXT:    [[TMP2:%.*]] = icmp eq i32* [[TMP0:%.*]], null
43; COUNTER3-NEXT:    call void @llvm.assume(i1 true) [ "nonnull"(i32* [[TMP0]]) ]
44; COUNTER3-NEXT:    ret i1 [[TMP2]]
45;
46  %2 = icmp eq i32* %0, null
47  call void @llvm.assume(i1 true) ["nonnull"(i32* %0)]
48  ret i1 %2
49}
50
51define dso_local i32 @test4(i32* readonly %0, i1 %cond) {
52; COUNTER1-LABEL: @test4(
53; COUNTER1-NEXT:    call void @llvm.assume(i1 true) [ "dereferenceable"(i32* [[TMP0:%.*]], i32 4) ]
54; COUNTER1-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
55; COUNTER1:       B:
56; COUNTER1-NEXT:    br label [[A]]
57; COUNTER1:       A:
58; COUNTER1-NEXT:    [[TMP2:%.*]] = icmp eq i32* [[TMP0]], null
59; COUNTER1-NEXT:    br i1 [[TMP2]], label [[TMP5:%.*]], label [[TMP3:%.*]]
60; COUNTER1:       3:
61; COUNTER1-NEXT:    [[TMP4:%.*]] = load i32, i32* [[TMP0]], align 4
62; COUNTER1-NEXT:    br label [[TMP5]]
63; COUNTER1:       5:
64; COUNTER1-NEXT:    [[TMP6:%.*]] = phi i32 [ [[TMP4]], [[TMP3]] ], [ 0, [[A]] ]
65; COUNTER1-NEXT:    ret i32 [[TMP6]]
66;
67; COUNTER2-LABEL: @test4(
68; COUNTER2-NEXT:    call void @llvm.assume(i1 true) [ "dereferenceable"(i32* [[TMP0:%.*]], i32 4) ]
69; COUNTER2-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
70; COUNTER2:       B:
71; COUNTER2-NEXT:    br label [[A]]
72; COUNTER2:       A:
73; COUNTER2-NEXT:    br i1 false, label [[TMP4:%.*]], label [[TMP2:%.*]]
74; COUNTER2:       2:
75; COUNTER2-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP0]], align 4
76; COUNTER2-NEXT:    br label [[TMP4]]
77; COUNTER2:       4:
78; COUNTER2-NEXT:    [[TMP5:%.*]] = phi i32 [ [[TMP3]], [[TMP2]] ], [ 0, [[A]] ]
79; COUNTER2-NEXT:    ret i32 [[TMP5]]
80;
81; COUNTER3-LABEL: @test4(
82; COUNTER3-NEXT:    call void @llvm.assume(i1 true) [ "dereferenceable"(i32* [[TMP0:%.*]], i32 4) ]
83; COUNTER3-NEXT:    br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
84; COUNTER3:       B:
85; COUNTER3-NEXT:    br label [[A]]
86; COUNTER3:       A:
87; COUNTER3-NEXT:    br i1 false, label [[TMP4:%.*]], label [[TMP2:%.*]]
88; COUNTER3:       2:
89; COUNTER3-NEXT:    [[TMP3:%.*]] = load i32, i32* [[TMP0]], align 4
90; COUNTER3-NEXT:    br label [[TMP4]]
91; COUNTER3:       4:
92; COUNTER3-NEXT:    [[TMP5:%.*]] = phi i32 [ [[TMP3]], [[TMP2]] ], [ 0, [[A]] ]
93; COUNTER3-NEXT:    ret i32 [[TMP5]]
94;
95  call void @llvm.assume(i1 true) ["dereferenceable"(i32* %0, i32 4)]
96  br i1 %cond, label %A, label %B
97
98B:
99  br label %A
100
101A:
102  %2 = icmp eq i32* %0, null
103  br i1 %2, label %5, label %3
104
1053:                                                ; preds = %1
106  %4 = load i32, i32* %0, align 4
107  br label %5
108
1095:                                                ; preds = %1, %3
110  %6 = phi i32 [ %4, %3 ], [ 0, %A ]
111  ret i32 %6
112}
113