1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
4 ; RUN: opt < %s -passes=instcombine --debug-counter=assume-queries-counter=0 -S | FileCheck %s --check-prefixes=COUNTER1
5 ; RUN: opt < %s -passes=instcombine --debug-counter=assume-queries-counter=1-2 -S | FileCheck %s --check-prefixes=COUNTER2
6 ; RUN: opt < %s -passes=instcombine --debug-counter=assume-queries-counter=2-6 -S | FileCheck %s --check-prefixes=COUNTER3
9 declare void @llvm.assume(i1)
11 define dso_local i1 @test1(ptr readonly %0) {
12 ; COUNTER1-LABEL: @test1(
13 ; COUNTER1-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0:%.*]]) ]
14 ; COUNTER1-NEXT: ret i1 false
16 ; COUNTER2-LABEL: @test1(
17 ; COUNTER2-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0:%.*]]) ]
18 ; COUNTER2-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
19 ; COUNTER2-NEXT: ret i1 [[TMP2]]
21 ; COUNTER3-LABEL: @test1(
22 ; COUNTER3-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0:%.*]]) ]
23 ; COUNTER3-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
24 ; COUNTER3-NEXT: ret i1 [[TMP2]]
26 call void @llvm.assume(i1 true) ["nonnull"(ptr %0)]
27 %2 = icmp eq ptr %0, null
31 define dso_local i1 @test2(ptr readonly %0) {
32 ; COUNTER1-LABEL: @test2(
33 ; COUNTER1-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0:%.*]], null
34 ; COUNTER1-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0]]) ]
35 ; COUNTER1-NEXT: ret i1 [[TMP2]]
37 ; COUNTER2-LABEL: @test2(
38 ; COUNTER2-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0:%.*]]) ]
39 ; COUNTER2-NEXT: ret i1 false
41 ; COUNTER3-LABEL: @test2(
42 ; COUNTER3-NEXT: call void @llvm.assume(i1 true) [ "nonnull"(ptr [[TMP0:%.*]]) ]
43 ; COUNTER3-NEXT: ret i1 false
45 %2 = icmp eq ptr %0, null
46 call void @llvm.assume(i1 true) ["nonnull"(ptr %0)]
50 define dso_local i32 @test4(ptr readonly %0, i1 %cond) {
51 ; COUNTER1-LABEL: @test4(
52 ; COUNTER1-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(ptr [[TMP0:%.*]], i32 4) ]
53 ; COUNTER1-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
55 ; COUNTER1-NEXT: br label [[A]]
57 ; COUNTER1-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
58 ; COUNTER1-NEXT: br i1 [[TMP2]], label [[TMP5:%.*]], label [[TMP3:%.*]]
60 ; COUNTER1-NEXT: [[TMP4:%.*]] = load i32, ptr [[TMP0]], align 4
61 ; COUNTER1-NEXT: br label [[TMP5]]
63 ; COUNTER1-NEXT: [[TMP6:%.*]] = phi i32 [ [[TMP4]], [[TMP3]] ], [ 0, [[A]] ]
64 ; COUNTER1-NEXT: ret i32 [[TMP6]]
66 ; COUNTER2-LABEL: @test4(
67 ; COUNTER2-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(ptr [[TMP0:%.*]], i32 4) ]
68 ; COUNTER2-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
70 ; COUNTER2-NEXT: br label [[A]]
72 ; COUNTER2-NEXT: [[TMP2:%.*]] = icmp eq ptr [[TMP0]], null
73 ; COUNTER2-NEXT: br i1 [[TMP2]], label [[TMP5:%.*]], label [[TMP3:%.*]]
75 ; COUNTER2-NEXT: [[TMP4:%.*]] = load i32, ptr [[TMP0]], align 4
76 ; COUNTER2-NEXT: br label [[TMP5]]
78 ; COUNTER2-NEXT: [[TMP6:%.*]] = phi i32 [ [[TMP4]], [[TMP3]] ], [ 0, [[A]] ]
79 ; COUNTER2-NEXT: ret i32 [[TMP6]]
81 ; COUNTER3-LABEL: @test4(
82 ; COUNTER3-NEXT: call void @llvm.assume(i1 true) [ "dereferenceable"(ptr [[TMP0:%.*]], i32 4) ]
83 ; COUNTER3-NEXT: br i1 [[COND:%.*]], label [[A:%.*]], label [[B:%.*]]
85 ; COUNTER3-NEXT: br label [[A]]
87 ; COUNTER3-NEXT: br i1 false, label [[TMP4:%.*]], label [[TMP2:%.*]]
89 ; COUNTER3-NEXT: [[TMP3:%.*]] = load i32, ptr [[TMP0]], align 4
90 ; COUNTER3-NEXT: br label [[TMP4]]
92 ; COUNTER3-NEXT: [[TMP5:%.*]] = phi i32 [ [[TMP3]], [[TMP2]] ], [ poison, [[A]] ]
93 ; COUNTER3-NEXT: ret i32 [[TMP5]]
95 call void @llvm.assume(i1 true) ["dereferenceable"(ptr %0, i32 4)]
96 br i1 %cond, label %A, label %B
102 %2 = icmp eq ptr %0, null
103 br i1 %2, label %5, label %3
106 %4 = load i32, ptr %0, align 4
110 %6 = phi i32 [ %4, %3 ], [ 0, %A ]