File: call-intrin.mlir

package info (click to toggle)
llvm-toolchain-18 1%3A18.1.8-18
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 1,908,340 kB
  • sloc: cpp: 6,667,937; ansic: 1,440,452; asm: 883,619; python: 230,549; objc: 76,880; f90: 74,238; lisp: 35,989; pascal: 16,571; sh: 10,229; perl: 7,459; ml: 5,047; awk: 3,523; makefile: 2,987; javascript: 2,149; xml: 892; fortran: 649; cs: 573
file content (107 lines) | stat: -rw-r--r-- 3,906 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// RUN: mlir-translate -mlir-to-llvmir -split-input-file -verify-diagnostics %s | FileCheck %s

// CHECK: define <4 x float> @round_sse41() {
// CHECK:  %1 = call reassoc <4 x float> @llvm.x86.sse41.round.ss(<4 x float> {{.*}}, <4 x float> {{.*}}, i32 1)
// CHECK:  ret <4 x float> %1
// CHECK: }
llvm.func @round_sse41() -> vector<4xf32> {
  %0 = llvm.mlir.constant(1 : i32) : i32
  %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
  %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}
  llvm.return %res: vector<4xf32>
}

// -----

// CHECK: define float @round_overloaded() {
// CHECK:   %1 = call float @llvm.round.f32(float 1.000000e+00)
// CHECK:   ret float %1
// CHECK: }
llvm.func @round_overloaded() -> f32 {
  %0 = llvm.mlir.constant(1.0 : f32) : f32
  %res = llvm.call_intrinsic "llvm.round"(%0) : (f32) -> f32 {}
  llvm.return %res: f32
}

// -----

// CHECK: define void @lifetime_start() {
// CHECK:   %1 = alloca float, i8 1, align 4
// CHECK:   call void @llvm.lifetime.start.p0(i64 4, ptr %1)
// CHECK:   ret void
// CHECK: }
llvm.func @lifetime_start() {
  %0 = llvm.mlir.constant(4 : i64) : i64
  %1 = llvm.mlir.constant(1 : i8) : i8
  %2 = llvm.alloca %1 x f32 : (i8) -> !llvm.ptr
  llvm.call_intrinsic "llvm.lifetime.start"(%0, %2) : (i64, !llvm.ptr) -> () {}
  llvm.return
}

// -----

// CHECK-LABEL: define void @variadic()
llvm.func @variadic() {
  %0 = llvm.mlir.constant(1 : i8) : i8
  %1 = llvm.alloca %0 x f32 : (i8) -> !llvm.ptr
  // CHECK: call void (...) @llvm.localescape(ptr %1, ptr %1)
  llvm.call_intrinsic "llvm.localescape"(%1, %1) : (!llvm.ptr, !llvm.ptr) -> ()
  llvm.return
}

// -----

llvm.func @no_intrinsic() {
  // expected-error@below {{could not find LLVM intrinsic: "llvm.does_not_exist"}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  llvm.call_intrinsic "llvm.does_not_exist"() : () -> ()
  llvm.return
}

// -----

llvm.func @bad_types() {
  %0 = llvm.mlir.constant(1 : i8) : i8
  // expected-error@below {{call intrinsic signature i8 (i8) to overloaded intrinsic "llvm.round" does not match any of the overloads}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  llvm.call_intrinsic "llvm.round"(%0) : (i8) -> i8 {}
  llvm.return
}

// -----

llvm.func @bad_result() {
  // expected-error @below {{intrinsic call returns void but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> ()
  llvm.return
}

// -----

llvm.func @bad_result() {
  // expected-error @below {{intrinsic call returns <8 x float> but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<8xf32>)
  llvm.return
}

// -----

llvm.func @bad_args() {
  // expected-error @below {{intrinsic call has 0 operands but "llvm.x86.sse41.round.ss" expects 3}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<4xf32>)
  llvm.return
}

// -----

llvm.func @bad_args() {
  %0 = llvm.mlir.constant(1 : i64) : i64
  %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>
  // expected-error @below {{intrinsic call operand #2 has type i64 but "llvm.x86.sse41.round.ss" expects i32}}
  // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}
  %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i64) -> vector<4xf32> {fastmathFlags = #llvm.fastmath<reassoc>}
  llvm.return
}