125 lines · plain
1// RUN: mlir-translate -mlir-to-llvmir -split-input-file -verify-diagnostics %s | FileCheck %s2 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> %16// CHECK: }7llvm.func @round_sse41() -> vector<4xf32> {8 %0 = llvm.mlir.constant(1 : i32) : i329 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>10 %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) {fastmathFlags = #llvm.fastmath<reassoc>} : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32>11 llvm.return %res: vector<4xf32>12}13 14// -----15 16// CHECK: define float @round_overloaded() {17// CHECK: %1 = call float @llvm.round.f32(float 1.000000e+00)18// CHECK: ret float %119// CHECK: }20llvm.func @round_overloaded() -> f32 {21 %0 = llvm.mlir.constant(1.0 : f32) : f3222 %res = llvm.call_intrinsic "llvm.round"(%0) {} : (f32) -> f3223 llvm.return %res: f3224}25 26// -----27 28// CHECK: define void @lifetime_start() {29// CHECK: %1 = alloca float, i8 1, align 430// CHECK: call void @llvm.lifetime.start.p0(ptr %1)31// CHECK: ret void32// CHECK: }33llvm.func @lifetime_start() {34 %0 = llvm.mlir.constant(1 : i8) : i835 %1 = llvm.alloca %0 x f32 : (i8) -> !llvm.ptr36 llvm.call_intrinsic "llvm.lifetime.start"(%1) {} : (!llvm.ptr) -> ()37 llvm.return38}39 40// -----41 42// CHECK-LABEL: define void @variadic()43llvm.func @variadic() {44 %0 = llvm.mlir.constant(1 : i8) : i845 %1 = llvm.alloca %0 x f32 : (i8) -> !llvm.ptr46 // CHECK: call void (...) @llvm.localescape(ptr %1, ptr %1)47 llvm.call_intrinsic "llvm.localescape"(%1, %1) : (!llvm.ptr, !llvm.ptr) -> ()48 llvm.return49}50 51// -----52 53llvm.func @no_intrinsic() {54 // expected-error@below {{could not find LLVM intrinsic: "llvm.does_not_exist"}}55 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}56 llvm.call_intrinsic "llvm.does_not_exist"() : () -> ()57 llvm.return58}59 60// -----61 62llvm.func @bad_types() {63 %0 = llvm.mlir.constant(1 : i8) : i864 // expected-error@below {{call intrinsic signature i8 (i8) to overloaded intrinsic "llvm.round" does not match any of the overloads}}65 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}66 llvm.call_intrinsic "llvm.round"(%0) {} : (i8) -> i867 llvm.return68}69 70// -----71 72llvm.func @bad_result() {73 // expected-error @below {{intrinsic call returns void but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}74 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}75 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> ()76 llvm.return77}78 79// -----80 81llvm.func @bad_result() {82 // expected-error @below {{intrinsic call returns <8 x float> but "llvm.x86.sse41.round.ss" actually returns <4 x float>}}83 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}84 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<8xf32>)85 llvm.return86}87 88// -----89 90llvm.func @bad_args() {91 // expected-error @below {{intrinsic call has 0 operands but "llvm.x86.sse41.round.ss" expects 3}}92 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}93 llvm.call_intrinsic "llvm.x86.sse41.round.ss"() : () -> (vector<4xf32>)94 llvm.return95}96 97// -----98 99llvm.func @bad_args() {100 %0 = llvm.mlir.constant(1 : i64) : i64101 %1 = llvm.mlir.constant(dense<0.2> : vector<4xf32>) : vector<4xf32>102 // expected-error @below {{intrinsic call operand #2 has type i64 but "llvm.x86.sse41.round.ss" expects i32}}103 // expected-error@below {{LLVM Translation failed for operation: llvm.call_intrinsic}}104 %res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) {fastmathFlags = #llvm.fastmath<reassoc>} : (vector<4xf32>, vector<4xf32>, i64) -> vector<4xf32>105 llvm.return106}107 108// -----109 110// CHECK-LABEL: intrinsic_call_arg_attrs111llvm.func @intrinsic_call_arg_attrs(%arg0: i32) -> i32 {112 // CHECK: call i32 @llvm.riscv.sha256sig0(i32 signext %{{.*}})113 %0 = llvm.call_intrinsic "llvm.riscv.sha256sig0"(%arg0) : (i32 {llvm.signext}) -> (i32)114 llvm.return %0 : i32115}116 117// -----118 119// CHECK-LABEL: intrinsic_element_type120llvm.func @intrinsic_element_type(%arg0: !llvm.ptr) {121 // CHECK: call i64 @llvm.aarch64.ldxr.p0(ptr elementtype(i8) %{{.*}})122 %0 = llvm.call_intrinsic "llvm.aarch64.ldxr.p0"(%arg0) : (!llvm.ptr {llvm.elementtype = i8}) -> i64123 llvm.return124}125