1 ; RUN: opt < %s -instcombine -S | FileCheck %s
3 declare void @llvm.experimental.guard(i1, ...)
5 define void @test_guard_adjacent_same_cond(i1 %A) {
6 ; CHECK-LABEL: @test_guard_adjacent_same_cond(
7 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %A) [ "deopt"() ]
9 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
10 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
11 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
12 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
13 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
14 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
15 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
16 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
17 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
18 call void(i1, ...) @llvm.experimental.guard( i1 %A )[ "deopt"() ]
22 define void @test_guard_adjacent_diff_cond(i1 %A, i1 %B, i1 %C) {
23 ; CHECK-LABEL: @test_guard_adjacent_diff_cond(
24 ; CHECK-NEXT: %1 = and i1 %A, %B
25 ; CHECK-NEXT: %2 = and i1 %1, %C
26 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %2, i32 123) [ "deopt"() ]
27 ; CHECK-NEXT: ret void
28 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
29 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]
30 call void(i1, ...) @llvm.experimental.guard( i1 %C, i32 789 )[ "deopt"() ]
34 ; This version tests for the common form where the conditions are
36 define void @test_guard_adjacent_diff_cond2(i32 %V1, i32 %V2) {
37 ; CHECK-LABEL: @test_guard_adjacent_diff_cond2(
38 ; CHECK-NEXT: %1 = and i32 %V1, %V2
39 ; CHECK-NEXT: %2 = icmp slt i32 %1, 0
40 ; CHECK-NEXT: %and = and i32 %V1, 255
41 ; CHECK-NEXT: %C = icmp ult i32 %and, 129
42 ; CHECK-NEXT: %3 = and i1 %2, %C
43 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %3, i32 123) [ "deopt"() ]
44 ; CHECK-NEXT: ret void
45 %A = icmp slt i32 %V1, 0
46 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
47 %B = icmp slt i32 %V2, 0
48 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]
49 %and = and i32 %V1, 255
50 %C = icmp sle i32 %and, 128
51 call void(i1, ...) @llvm.experimental.guard( i1 %C, i32 789 )[ "deopt"() ]
55 ; Might not be legal to hoist the load above the first guard since the
56 ; guard might control dereferenceability
57 define void @negative_load(i32 %V1, i32* %P) {
58 ; CHECK-LABEL: @negative_load
59 ; CHECK: @llvm.experimental.guard
60 ; CHECK: @llvm.experimental.guard
61 %A = icmp slt i32 %V1, 0
62 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
63 %V2 = load i32, i32* %P
64 %B = icmp slt i32 %V2, 0
65 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]
69 define void @deref_load(i32 %V1, i32* dereferenceable(4) %P) {
70 ; CHECK-LABEL: @deref_load
71 ; CHECK-NEXT: %V2 = load i32, i32* %P, align 4
72 ; CHECK-NEXT: %1 = and i32 %V2, %V1
73 ; CHECK-NEXT: %2 = icmp slt i32 %1, 0
74 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 %2, i32 123) [ "deopt"() ]
75 %A = icmp slt i32 %V1, 0
76 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
77 %V2 = load i32, i32* %P
78 %B = icmp slt i32 %V2, 0
79 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]
83 ; The divide might fault above the guard
84 define void @negative_div(i32 %V1, i32 %D) {
85 ; CHECK-LABEL: @negative_div
86 ; CHECK: @llvm.experimental.guard
87 ; CHECK: @llvm.experimental.guard
88 %A = icmp slt i32 %V1, 0
89 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
90 %V2 = udiv i32 %V1, %D
91 %B = icmp slt i32 %V2, 0
92 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]
96 ; Highlight the limit of the window in a case which would otherwise be mergable
97 define void @negative_window(i32 %V1, i32 %a, i32 %b, i32 %c, i32 %d) {
98 ; CHECK-LABEL: @negative_window
99 ; CHECK: @llvm.experimental.guard
100 ; CHECK: @llvm.experimental.guard
101 %A = icmp slt i32 %V1, 0
102 call void(i1, ...) @llvm.experimental.guard( i1 %A, i32 123 )[ "deopt"() ]
104 %V3 = add i32 %V2, %c
105 %V4 = add i32 %V3, %d
106 %B = icmp slt i32 %V4, 0
107 call void(i1, ...) @llvm.experimental.guard( i1 %B, i32 456 )[ "deopt"() ]