diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -768,17 +768,22 @@ // Misc operations. def LLVM_SelectOp : LLVM_Op<"select", - [Pure, AllTypesMatch<["trueValue", "falseValue", "res"]>]>, + [Pure, AllTypesMatch<["trueValue", "falseValue", "res"]>, + DeclareOpInterfaceMethods]>, LLVM_Builder< "$res = builder.CreateSelect($condition, $trueValue, $falseValue);"> { let arguments = (ins LLVM_ScalarOrVectorOf:$condition, - LLVM_Type:$trueValue, LLVM_Type:$falseValue); + LLVM_Type:$trueValue, LLVM_Type:$falseValue, + DefaultValuedAttr:$fastmathFlags); let results = (outs LLVM_Type:$res); let assemblyFormat = "operands attr-dict `:` type($condition) `,` type($res)"; string llvmInstName = "Select"; string mlirBuilder = [{ - $res = $_builder.create( + auto op = $_builder.create( $_location, $_resultType, $condition, $trueValue, $falseValue); + moduleImport.setFastmathFlagsAttr(inst, op); + $res = op; }]; } def LLVM_FreezeOp : LLVM_Op<"freeze", [SameOperandsAndResultType]> { diff --git a/mlir/test/Target/LLVMIR/llvmir.mlir b/mlir/test/Target/LLVMIR/llvmir.mlir --- a/mlir/test/Target/LLVMIR/llvmir.mlir +++ b/mlir/test/Target/LLVMIR/llvmir.mlir @@ -1911,6 +1911,10 @@ %19 = "llvm.intr.powi"(%arg0, %exp) {fastmathFlags = #llvm.fastmath} : (f32, i32) -> f32 // CHECK: call afn float @llvm.powi.f32.i32(float {{.*}}, i32 {{.*}}) %20 = "llvm.intr.powi"(%arg0, %exp) {fastmathFlags = #llvm.fastmath} : (f32, i32) -> f32 + + %21 = llvm.mlir.constant(true) : i1 +// CHECK: select contract i1 + %22 = llvm.select %21, %arg0, %20 {fastmathFlags = #llvm.fastmath} : i1, f32 llvm.return }