1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=gvn < %s | FileCheck %s
4 define i32 @test(ptr %p, i32 %v) {
6 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[P:%.*]]
7 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
8 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
9 ; CHECK-NEXT: ret i32 [[V]]
11 %load = load i32, ptr %p
12 %c = icmp eq i32 %load, %v
13 call void @llvm.assume(i1 %c)
17 define i32 @reverse(ptr %p, i32 %v) {
18 ; CHECK-LABEL: @reverse(
19 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[P:%.*]]
20 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
21 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
22 ; CHECK-NEXT: ret i32 [[V]]
24 %load = load i32, ptr %p
25 %c = icmp eq i32 %load, %v
26 call void @llvm.assume(i1 %c)
30 ; Lack of equivalance due to +0.0 vs -0.0
31 define float @neg_float_oeq(ptr %p, float %v) {
32 ; CHECK-LABEL: @neg_float_oeq(
33 ; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[P:%.*]]
34 ; CHECK-NEXT: [[C:%.*]] = fcmp oeq float [[LOAD]], [[V:%.*]]
35 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
36 ; CHECK-NEXT: ret float [[LOAD]]
38 %load = load float, ptr %p
39 %c = fcmp oeq float %load, %v
40 call void @llvm.assume(i1 %c)
44 ; Lack of equivalance due to +0.0 vs -0.0
45 define float @neg_float_ueq(ptr %p, float %v) {
46 ; CHECK-LABEL: @neg_float_ueq(
47 ; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[P:%.*]]
48 ; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[LOAD]], [[V:%.*]]
49 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
50 ; CHECK-NEXT: ret float [[LOAD]]
52 %load = load float, ptr %p
53 %c = fcmp ueq float %load, %v
54 call void @llvm.assume(i1 %c)
58 define float @float_oeq_constant(ptr %p) {
59 ; CHECK-LABEL: @float_oeq_constant(
60 ; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[P:%.*]]
61 ; CHECK-NEXT: [[C:%.*]] = fcmp oeq float [[LOAD]], 5.000000e+00
62 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
63 ; CHECK-NEXT: ret float 5.000000e+00
65 %load = load float, ptr %p
66 %c = fcmp oeq float %load, 5.0
67 call void @llvm.assume(i1 %c)
71 ; Lack of equivalance due to Nan
72 define float @neq_float_ueq_constant(ptr %p) {
73 ; CHECK-LABEL: @neq_float_ueq_constant(
74 ; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[P:%.*]]
75 ; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[LOAD]], 5.000000e+00
76 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
77 ; CHECK-NEXT: ret float [[LOAD]]
79 %load = load float, ptr %p
80 %c = fcmp ueq float %load, 5.0
81 call void @llvm.assume(i1 %c)
85 define float @float_ueq_constant_nnas(ptr %p) {
86 ; CHECK-LABEL: @float_ueq_constant_nnas(
87 ; CHECK-NEXT: [[LOAD:%.*]] = load float, ptr [[P:%.*]]
88 ; CHECK-NEXT: [[C:%.*]] = fcmp nnan ueq float [[LOAD]], 5.000000e+00
89 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
90 ; CHECK-NEXT: ret float 5.000000e+00
92 %load = load float, ptr %p
93 %c = fcmp nnan ueq float %load, 5.0
94 call void @llvm.assume(i1 %c)
98 define i32 @test2(ptr %p, i32 %v) {
99 ; CHECK-LABEL: @test2(
100 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[P:%.*]]
101 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
102 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
103 ; CHECK-NEXT: ret i32 [[V]]
105 %load = load i32, ptr %p
106 %c = icmp eq i32 %load, %v
107 call void @llvm.assume(i1 %c)
108 %load2 = load i32, ptr %p
112 define i32 @test3(ptr %p, i32 %v, i1 %arg) {
113 ; CHECK-LABEL: @test3(
114 ; CHECK-NEXT: [[LOAD:%.*]] = load i32, ptr [[P:%.*]]
115 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
116 ; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
117 ; CHECK-NEXT: br i1 %arg, label [[TAKEN:%.*]], label [[MERGE:%.*]]
119 ; CHECK-NEXT: br label [[MERGE]]
121 ; CHECK-NEXT: ret i32 [[V]]
123 %load = load i32, ptr %p
124 %c = icmp eq i32 %load, %v
125 call void @llvm.assume(i1 %c)
126 br i1 %arg, label %taken, label %merge
133 define i32 @trivial_constants(ptr %p, i1 %arg) {
134 ; CHECK-LABEL: @trivial_constants(
135 ; CHECK-NEXT: br i1 %arg, label [[TAKEN:%.*]], label [[MERGE:%.*]]
137 ; CHECK-NEXT: br label [[MERGE]]
139 ; CHECK-NEXT: ret i32 0
141 %c = icmp eq i32 0, 0
142 call void @llvm.assume(i1 %c)
143 br i1 %arg, label %taken, label %merge
150 define i32 @conflicting_constants(ptr %p, i1 %arg) {
151 ; CHECK-LABEL: @conflicting_constants(
152 ; CHECK-NEXT: store i8 poison, ptr null
153 ; CHECK-NEXT: br i1 %arg, label [[TAKEN:%.*]], label [[MERGE:%.*]]
155 ; CHECK-NEXT: br label [[MERGE]]
157 ; CHECK-NEXT: ret i32 1
159 %c = icmp eq i32 0, 5
160 call void @llvm.assume(i1 %c)
161 br i1 %arg, label %taken, label %merge
168 declare void @llvm.assume(i1)