[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic
Lily Orth-Smith via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 26 10:27:00 PDT 2023
electriclilies updated this revision to Diff 526115.
electriclilies added a comment.
fix test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151492/new/
https://reviews.llvm.org/D151492
Files:
mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
mlir/test/Dialect/LLVMIR/call-intrin.mlir
Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===================================================================
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -5,13 +5,13 @@
// CHECK: declare ptr @malloc(i64)
// CHECK: declare void @free(ptr)
// CHECK: define <4 x float> @round_sse41() {
-// CHECK: %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> <float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000>, <4 x float> <float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000>, i32 1)
+// CHECK: %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> <float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000>, <4 x float> <float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000, float 0x3FC99999A0000000>, i32 1) {fastmathFlags = #llvm.fastmath<reassoc>}
// 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> {}
+ %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>
}
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===================================================================
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
+++ mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
@@ -95,7 +95,7 @@
/// Builder for LLVM_CallIntrinsicOp
static LogicalResult
-convertCallLLVMIntrinsicOp(CallIntrinsicOp &op, llvm::IRBuilderBase &builder,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase &builder,
LLVM::ModuleTranslation &moduleTranslation) {
llvm::Module *module = builder.GetInsertBlock()->getModule();
llvm::Intrinsic::ID id =
@@ -114,6 +114,8 @@
} else {
fn = llvm::Intrinsic::getDeclaration(module, id, {});
}
+ FastmathFlagsInterface itf = op;
+ builder.setFastMathFlags(getFastmathFlags(itf));
auto *inst =
builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
Index: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
===================================================================
--- mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
+++ mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td
@@ -867,19 +867,24 @@
// CallIntrinsicOp
//===--------------------------------------------------------------------===//
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp
+ : LLVM_Op<"call_intrinsic",
+ [DeclareOpInterfaceMethods<FastmathFlagsInterface>]> {
let summary = "Call to an LLVM intrinsic function.";
let description = [{
Call the specified llvm intrinsic. If the intrinsic is overloaded, use
the MLIR function type of this op to determine which intrinsic to call.
}];
- let arguments = (ins StrAttr:$intrin, Variadic<LLVM_Type>:$args);
+ let arguments = (ins StrAttr:$intrin, Variadic<LLVM_Type>:$args,
+ DefaultValuedAttr<LLVM_FastmathFlagsAttr,
+ "{}">:$fastmathFlags);
let results = (outs Variadic<LLVM_Type>:$results);
let llvmBuilder = [{
return convertCallLLVMIntrinsicOp(op, builder, moduleTranslation);
}];
let assemblyFormat = [{
- $intrin `(` $args `)` `:` functional-type($args, $results) attr-dict
+ $intrin `(` $args `)` `:` functional-type($args, $results)
+ custom<LLVMOpAttrs>(attr-dict)
}];
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151492.526115.patch
Type: text/x-patch
Size: 3935 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230526/ed35a576/attachment-0001.bin>
More information about the cfe-commits
mailing list