1 // RUN: mlir-translate -mlir-to-llvmir -split-input-file -verify-diagnostics %s | FileCheck %s
3 // CHECK: define <4 x float> @round_sse41() {
4 // CHECK: %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> {{.*}}, <4 x float> {{.*}}, i32 1)
5 // CHECK: ret <4 x float> %1
7 llvm.func @round_sse41() -> vector<4xf32> {
8 %0 = llvm.mlir.constant(1 : i32) : i32
9 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
10 %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}
11 llvm.return %res: vector<4xf32>
16 // CHECK: define float @round_overloaded() {
17 // CHECK: %1 = call float @llvm.round.f32(float 1.000000e+00)
18 // CHECK: ret float %1
20 llvm.func @round_overloaded() -> f32 {
21 %0 = llvm.mlir.constant(1.0 : f32) : f32
22 %res = llvm.call_intrinsic "llvm.round"(%0) : (f32) -> f32 {}
28 // CHECK: define void @lifetime_start() {
29 // CHECK: %1 = alloca float, i8 1, align 4
30 // CHECK: call void @llvm.lifetime.start.p0(i64 4, ptr %1)
33 llvm.func @lifetime_start() {
34 %0 = llvm.mlir.constant(4 : i64) : i64
35 %1 = llvm.mlir.constant(1 : i8) : i8
36 %2 = llvm.alloca %1 x f32 : (i8) -> !llvm.ptr
37 llvm.call_intrinsic "llvm.lifetime.start"(%0, %2) : (i64, !llvm.ptr) -> () {}
43 // CHECK-LABEL: define void @variadic()
44 llvm.func @variadic() {
45 %0 = llvm.mlir.constant(1 : i8) : i8
46 %1 = llvm.alloca %0 x f32 : (i8) -> !llvm.ptr
47 // CHECK: call void (...) @llvm.localescape(ptr %1, ptr %1)
48 llvm.call_intrinsic "llvm.localescape"(%1, %1) : (!llvm.ptr, !llvm.ptr) -> ()
54 llvm.func @no_intrinsic() {
55 // expected-error@below {{could not find LLVM intrinsic: "llvm.does_not_exist"}}
56 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
57 llvm.call_intrinsic "llvm.does_not_exist"() : () -> ()
63 llvm.func @bad_types() {
64 %0 = llvm.mlir.constant(1 : i8) : i8
65 // expected-error@below {{call intrinsic signature i8 (i8) to overloaded intrinsic "llvm.round" does not match any of the overloads}}
66 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
67 llvm.call_intrinsic "llvm.round"(%0) : (i8) -> i8 {}
73 llvm.func @bad_result() {
74 // expected-error @below {{intrinsic call returns void but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}
75 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
76 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> ()
82 llvm.func @bad_result() {
83 // expected-error @below {{intrinsic call returns <8 x float> but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}
84 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
85 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<8xf32>)
91 llvm.func @bad_args() {
92 // expected-error @below {{intrinsic call has 0 operands but "llvm.x86.sse41.round.ss" expects 3}}
93 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
94 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<4xf32>)
100 llvm.func @bad_args() {
101 %0 = llvm.mlir.constant(1 : i64) : i64
102 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
103 // expected-error @below {{intrinsic call operand #2 has type i64 but "llvm.x86.sse41.round.ss" expects i32}}
104 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
105 %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i64) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}