[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Jeff Niu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9346dc6f675e: Add fastmath attributes to llvm.call_intrinsic 
(authored by electriclilies, committed by Mogball).

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> , <4 x float> , i32 1)
+// 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> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = 
#llvm.fastmath}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


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> , <4 x float> , i32 1)
+// 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> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 526117.
electriclilies added a comment.

fix


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> , <4 x float> , i32 1)
+// 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> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : 
(vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = 
#llvm.fastmath}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


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> , <4 x float> , i32 1)
+// 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> {}
+%res = llvm.call_intrinsic "llvm.x86.sse41.round.ss"(%1, %1, %0) : (vector<4xf32>, vector<4xf32>, i32) -> vector<4xf32> {fastmathFlags = #llvm.fastmath}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-26 Thread Lily Orth-Smith via Phabricator via cfe-commits
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> , <4 x float> , i32 1)
+// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1) 
{fastmathFlags = #llvm.fastmath}
 // 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}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


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> , <4 x float> , i32 1)
+// CHECK:  %1 = call <4 x float> @llvm.x86.sse41.round.ss(<4 x float> , <4 x float> , i32 1) {fastmathFlags = #llvm.fastmath}
 // 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}
 llvm.return %res: vector<4xf32>
 }
 
Index: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp
===
--- 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 525831.
electriclilies added a comment.

format


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
@@ -11,7 +11,7 @@
 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}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args,
+   DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -11,7 +11,7 @@
 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}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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, 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

electriclilies wrote:
> Mogball wrote:
> > Mogball wrote:
> > > electriclilies wrote:
> > > > Mogball wrote:
> > > > > Mogball wrote:
> > > > > > electriclilies wrote:
> > > > > > > Mogball wrote:
> > > > > > > > I think the problem with the cast below is that this is passed 
> > > > > > > > by reference. You should not pass operation handles by 
> > > > > > > > reference.
> > > > > > > I think I can't pass it by value because it's const though.. 
> > > > > > where is it const?
> > > > > if it were const, it wouldn't bind to a non-const reference anyways
> > > > If I just try to pass the op into the dyn_cast, it gives this error, 
> > > > which says that the op is a const
> > > > ```
> > > > /home/lily/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:64:65:
> > > >  error: cannot initialize a parameter of type 'mlir::Operation *' with 
> > > > an rvalue of type 'const mlir::LLVM::CallIntrinsicOp *
> > > > ```
> > > did you drop the reference?
> > ```
> > CallIntrinsicOp 
> > ```
> > 
> > delete the `&`. You should never do this for ops anyways
> OK, I think I can upcast it to an Operation& to avoid this, and get rid of 
> the copy
Dropped the reference, it works now


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball accepted this revision.
Mogball added inline comments.
This revision is now accepted and ready to land.



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:878
 }];
-  let arguments = (ins StrAttr:$intrin, Variadic:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args, 
DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$results);

here as well please



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:883
   }];
   let assemblyFormat = [{
+$intrin `(` $args `)` `:` functional-type($args, $results) 
custom(attr-dict)

and this one


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 525815.
electriclilies added a comment.

fixes


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
@@ -11,7 +11,7 @@
 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}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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,21 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp
+: LLVM_Op<"call_intrinsic",
+  [DeclareOpInterfaceMethods]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args, 
DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -11,7 +11,7 @@
 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}
 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 , llvm::IRBuilderBase ,
+convertCallLLVMIntrinsicOp(CallIntrinsicOp op, llvm::IRBuilderBase ,
LLVM::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: 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

Mogball wrote:
> Mogball wrote:
> > electriclilies wrote:
> > > Mogball wrote:
> > > > Mogball wrote:
> > > > > electriclilies wrote:
> > > > > > Mogball wrote:
> > > > > > > I think the problem with the cast below is that this is passed by 
> > > > > > > reference. You should not pass operation handles by reference.
> > > > > > I think I can't pass it by value because it's const though.. 
> > > > > where is it const?
> > > > if it were const, it wouldn't bind to a non-const reference anyways
> > > If I just try to pass the op into the dyn_cast, it gives this error, 
> > > which says that the op is a const
> > > ```
> > > /home/lily/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:64:65:
> > >  error: cannot initialize a parameter of type 'mlir::Operation *' with an 
> > > rvalue of type 'const mlir::LLVM::CallIntrinsicOp *
> > > ```
> > did you drop the reference?
> ```
> CallIntrinsicOp 
> ```
> 
> delete the `&`. You should never do this for ops anyways
OK, I think I can upcast it to an Operation& to avoid this, and get rid of the 
copy


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

Mogball wrote:
> electriclilies wrote:
> > Mogball wrote:
> > > Mogball wrote:
> > > > electriclilies wrote:
> > > > > Mogball wrote:
> > > > > > I think the problem with the cast below is that this is passed by 
> > > > > > reference. You should not pass operation handles by reference.
> > > > > I think I can't pass it by value because it's const though.. 
> > > > where is it const?
> > > if it were const, it wouldn't bind to a non-const reference anyways
> > If I just try to pass the op into the dyn_cast, it gives this error, which 
> > says that the op is a const
> > ```
> > /home/lily/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:64:65:
> >  error: cannot initialize a parameter of type 'mlir::Operation *' with an 
> > rvalue of type 'const mlir::LLVM::CallIntrinsicOp *
> > ```
> did you drop the reference?
```
CallIntrinsicOp 
```

delete the `&`. You should never do this for ops anyways


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

electriclilies wrote:
> Mogball wrote:
> > Mogball wrote:
> > > electriclilies wrote:
> > > > Mogball wrote:
> > > > > I think the problem with the cast below is that this is passed by 
> > > > > reference. You should not pass operation handles by reference.
> > > > I think I can't pass it by value because it's const though.. 
> > > where is it const?
> > if it were const, it wouldn't bind to a non-const reference anyways
> If I just try to pass the op into the dyn_cast, it gives this error, which 
> says that the op is a const
> ```
> /home/lily/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:64:65:
>  error: cannot initialize a parameter of type 'mlir::Operation *' with an 
> rvalue of type 'const mlir::LLVM::CallIntrinsicOp *
> ```
did you drop the reference?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

Mogball wrote:
> Mogball wrote:
> > electriclilies wrote:
> > > Mogball wrote:
> > > > I think the problem with the cast below is that this is passed by 
> > > > reference. You should not pass operation handles by reference.
> > > I think I can't pass it by value because it's const though.. 
> > where is it const?
> if it were const, it wouldn't bind to a non-const reference anyways
If I just try to pass the op into the dyn_cast, it gives this error, which says 
that the op is a const
```
/home/lily/modular/third-party/llvm-project/llvm/include/llvm/Support/Casting.h:64:65:
 error: cannot initialize a parameter of type 'mlir::Operation *' with an 
rvalue of type 'const mlir::LLVM::CallIntrinsicOp *
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

Mogball wrote:
> electriclilies wrote:
> > Mogball wrote:
> > > I think the problem with the cast below is that this is passed by 
> > > reference. You should not pass operation handles by reference.
> > I think I can't pass it by value because it's const though.. 
> where is it const?
if it were const, it wouldn't bind to a non-const reference anyways


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

electriclilies wrote:
> Mogball wrote:
> > I think the problem with the cast below is that this is passed by 
> > reference. You should not pass operation handles by reference.
> I think I can't pass it by value because it's const though.. 
where is it const?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

Mogball wrote:
> I think the problem with the cast below is that this is passed by reference. 
> You should not pass operation handles by reference.
I think I can't pass it by value because it's const though.. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Jeff Niu via Phabricator via cfe-commits
Mogball added inline comments.



Comment at: mlir/include/mlir/Dialect/LLVMIR/LLVMIntrinsicOps.td:870
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic", 
[DeclareOpInterfaceMethods]> {
   let summary = "Call to an LLVM intrinsic function.";

please fit this definition into 80 characters wide



Comment at: mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:98
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
LLVM::ModuleTranslation ) {

I think the problem with the cast below is that this is passed by reference. 
You should not pass operation handles by reference.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:130
 
-  llvm::CallInst *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));

ftynse wrote:
> Don't use `auto` unless the type is obvious from context (e.g., the RHS is a 
> cast) or difficult to spell.
This auto was already here, I changed it in previous commit. It showed up in 
the diff because I hadn't squashed my changes yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 525779.
electriclilies added a comment.

Remove whitespace


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
@@ -11,7 +11,7 @@
 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}
 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
@@ -114,6 +114,9 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  Operation* op2 = op;
+  if (auto fmf = dyn_cast(op2))
+builder.setFastMathFlags(getFastmathFlags(fmf));
 
   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,19 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic", 
[DeclareOpInterfaceMethods]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args, 
DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -11,7 +11,7 @@
 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}
 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
@@ -114,6 +114,9 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  Operation* op2 = op;
+  if (auto fmf = dyn_cast(op2))
+builder.setFastMathFlags(getFastmathFlags(fmf));
 
   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,19 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic", [DeclareOpInterfaceMethods]> {
   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 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Alex Zinenko via Phabricator via cfe-commits
ftynse added inline comments.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:367
   // that can be valid on the real entry.
-  // This is what I want to do
   AttributeList NewAttrs = AttributeList::get(Ctx, 
AttributeList::FunctionIndex,

electriclilies wrote:
> ftynse wrote:
> > This cleanup should go in a separate commit.
> For some reason arcanist is showing the diff between my 2 latest commits, not 
> between main and my branch, I added this in a previous commit then removed it 
> in my final clean up commit.. 
If you create it with `arc`, the command indicates with respect to which other 
commit the diff is taken, e.g. `arc diff HEAD^` is the diff between the 
currently checked out commit and the previous one (`HEAD^`). You can do several 
steps (`HEAD^^^` for three) or specify the commit hash explicitly.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies updated this revision to Diff 525778.
electriclilies added a comment.

Squish commits


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
@@ -11,7 +11,7 @@
 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}
 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
@@ -93,6 +93,7 @@
   return llvm::Intrinsic::getDeclaration(module, id, overloadedArgTysRef);
 }
 
+
 /// Builder for LLVM_CallIntrinsicOp
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
@@ -114,9 +115,13 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  Operation* op2 = op;
+  if (auto fmf = dyn_cast(op2))
+builder.setFastMathFlags(getFastmathFlags(fmf));
 
   auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
+
   if (op.getNumResults() == 1)
 moduleTranslation.mapValue(op->getResults().front()) = inst;
   return success();
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,19 @@
 // CallIntrinsicOp
 //======//
 
-def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic"> {
+def LLVM_CallIntrinsicOp : LLVM_Op<"call_intrinsic", 
[DeclareOpInterfaceMethods]> {
   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:$args);
+  let arguments = (ins StrAttr:$intrin, Variadic:$args, 
DefaultValuedAttr:$fastmathFlags);
   let results = (outs Variadic:$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(attr-dict)
   }];
 }
 


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -11,7 +11,7 @@
 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}
 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
@@ -93,6 +93,7 @@
   return llvm::Intrinsic::getDeclaration(module, id, overloadedArgTysRef);
 }
 
+
 /// Builder for LLVM_CallIntrinsicOp
 static LogicalResult
 convertCallLLVMIntrinsicOp(CallIntrinsicOp , llvm::IRBuilderBase ,
@@ -114,9 +115,13 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
+  Operation* op2 = op;
+  if (auto fmf = dyn_cast(op2))
+builder.setFastMathFlags(getFastmathFlags(fmf));
 
   auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
+
   if (op.getNumResults() == 1)
 moduleTranslation.mapValue(op->getResults().front()) = inst;
   return success();
Index: 

[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added inline comments.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:367
   // that can be valid on the real entry.
-  // This is what I want to do
   AttributeList NewAttrs = AttributeList::get(Ctx, 
AttributeList::FunctionIndex,

ftynse wrote:
> This cleanup should go in a separate commit.
For some reason arcanist is showing the diff between my 2 latest commits, not 
between main and my branch, I added this in a previous commit then removed it 
in my final clean up commit.. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies added a comment.

For some reason the diff is showing the difference between 2 commits on my 
branch, anyone know how to fix this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Alex Zinenko via Phabricator via cfe-commits
ftynse added inline comments.



Comment at: clang/lib/CodeGen/CGHLSLRuntime.cpp:367
   // that can be valid on the real entry.
-  // This is what I want to do
   AttributeList NewAttrs = AttributeList::get(Ctx, 
AttributeList::FunctionIndex,

This cleanup should go in a separate commit.



Comment at: 
mlir/lib/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.cpp:130
 
-  llvm::CallInst *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));

Don't use `auto` unless the type is obvious from context (e.g., the RHS is a 
cast) or difficult to spell.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151492/new/

https://reviews.llvm.org/D151492

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151492: Add fastmath attributes to llvm.call_intrinsic

2023-05-25 Thread Lily Orth-Smith via Phabricator via cfe-commits
electriclilies created this revision.
Herald added subscribers: bviyer, Moerafaat, zero9178, bzcheeseman, awarzynski, 
sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, 
jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, 
antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a reviewer: ftynse.
Herald added a reviewer: dcaballe.
Herald added a project: All.
electriclilies requested review of this revision.
Herald added a reviewer: nicolasvasilache.
Herald added subscribers: cfe-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: clang, MLIR.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151492

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  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
@@ -11,7 +11,7 @@
 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}
 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
@@ -16,15 +16,12 @@
 #include "mlir/Support/LLVM.h"
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 
-//#include "llvm/IR/Attributes.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
 #include "llvm/IR/Operator.h"
 
-#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
-
 using namespace mlir;
 using namespace mlir::LLVM;
 using mlir::LLVM::detail::createIntrinsicCall;
@@ -118,16 +115,11 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module, id, {});
   }
-  llvm::errs() << "hi\n";
   Operation* op2 = op;
-  llvm::errs() << "hi2\n";
-  if (auto fmf = dyn_cast(op2)) {
-llvm::errs() << "setting fastmath flags\n";
+  if (auto fmf = dyn_cast(op2))
 builder.setFastMathFlags(getFastmathFlags(fmf));
-llvm::errs() << "done\n";
-  }
 
-  llvm::CallInst *inst =
+  auto *inst =
   builder.CreateCall(fn, moduleTranslation.lookupValues(op.getOperands()));
 
   if (op.getNumResults() == 1)
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -364,7 +364,6 @@
 
   // Copy function attributes over, we have no argument or return attributes
   // that can be valid on the real entry.
-  // This is what I want to do
   AttributeList NewAttrs = AttributeList::get(Ctx, 
AttributeList::FunctionIndex,
   
Fn->getAttributes().getFnAttrs());
   EntryFn->setAttributes(NewAttrs);


Index: mlir/test/Dialect/LLVMIR/call-intrin.mlir
===
--- mlir/test/Dialect/LLVMIR/call-intrin.mlir
+++ mlir/test/Dialect/LLVMIR/call-intrin.mlir
@@ -11,7 +11,7 @@
 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}
 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
@@ -16,15 +16,12 @@
 #include "mlir/Support/LLVM.h"
 #include "mlir/Target/LLVMIR/ModuleTranslation.h"
 
-//#include "llvm/IR/Attributes.h"
 #include "llvm/IR/IRBuilder.h"
 #include "llvm/IR/InlineAsm.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/MatrixBuilder.h"
 #include "llvm/IR/Operator.h"
 
-#include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h"
-
 using namespace mlir;
 using namespace mlir::LLVM;
 using mlir::LLVM::detail::createIntrinsicCall;
@@ -118,16 +115,11 @@
   } else {
 fn = llvm::Intrinsic::getDeclaration(module,