Skip to content

Commit e38eb33

Browse files
author
Zhang Yan
committed
change to optional attr
1 parent a8cf350 commit e38eb33

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

mlir/include/mlir/Dialect/Arith/IR/ArithOps.td

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,8 +1209,7 @@ def Arith_ExtFOp : Arith_FToFCastOp<"extf", [DeclareOpInterfaceMethods<ArithFast
12091209
let hasVerifier = 1;
12101210
let hasFolder = 1;
12111211

1212-
let arguments = (ins FloatLike:$in, DefaultValuedAttr<
1213-
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath);
1212+
let arguments = (ins FloatLike:$in, OptionalAttr<Arith_FastMathAttr>:$fastmath);
12141213
let results = (outs FloatLike:$out);
12151214

12161215
let assemblyFormat = [{ $in (`fastmath` `` $fastmath^)?
@@ -1256,9 +1255,8 @@ def Arith_TruncFOp :
12561255
DeclareOpInterfaceMethods<ArithFastMathInterface>,
12571256
DeclareOpInterfaceMethods<CastOpInterface>]>,
12581257
Arguments<(ins FloatLike:$in,
1259-
DefaultValuedAttr<
1260-
Arith_FastMathAttr, "::mlir::arith::FastMathFlags::none">:$fastmath,
1261-
OptionalAttr<Arith_RoundingModeAttr>:$roundingmode)>,
1258+
OptionalAttr<Arith_RoundingModeAttr>:$roundingmode,
1259+
OptionalAttr<Arith_FastMathAttr>:$fastmath)>,
12621260
Results<(outs FloatLike:$out)> {
12631261
let summary = "cast from floating-point to narrower floating-point";
12641262
let description = [{

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,10 +1392,13 @@ LogicalResult arith::ExtSIOp::verify() {
13921392
OpFoldResult arith::ExtFOp::fold(FoldAdaptor adaptor) {
13931393
if (auto truncFOp = getOperand().getDefiningOp<TruncFOp>()) {
13941394
if (truncFOp.getOperand().getType() == getType()) {
1395-
arith::FastMathFlags truncFMF = truncFOp.getFastmath();
1395+
arith::FastMathFlags truncFMF =
1396+
truncFOp.getFastmath().value_or(arith::FastMathFlags::none);
13961397
bool isTruncContract =
13971398
bitEnumContainsAll(truncFMF, arith::FastMathFlags::contract);
1398-
arith::FastMathFlags extFMF = getFastmath();
1399+
arith::FastMathFlags extFMF =
1400+
getFastmath().value_or(arith::FastMathFlags::none);
1401+
;
13991402
bool isExtContract =
14001403
bitEnumContainsAll(extFMF, arith::FastMathFlags::contract);
14011404
if (isTruncContract && isExtContract) {

mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,23 +162,23 @@ func.func @uitofp(%arg0 : i32, %arg1 : i64) {
162162
// Checking conversion of integer types to floating point.
163163
// CHECK-LABEL: @fpext
164164
func.func @fpext(%arg0 : f16, %arg1 : f32) {
165-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : f16 to f32
165+
// CHECK-NEXT: = llvm.fpext {{.*}} : f16 to f32
166166
%0 = arith.extf %arg0: f16 to f32
167-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : f16 to f64
167+
// CHECK-NEXT: = llvm.fpext {{.*}} : f16 to f64
168168
%1 = arith.extf %arg0: f16 to f64
169-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : f32 to f64
169+
// CHECK-NEXT: = llvm.fpext {{.*}} : f32 to f64
170170
%2 = arith.extf %arg1: f32 to f64
171171
return
172172
}
173173

174174
// Checking conversion of integer types to floating point.
175175
// CHECK-LABEL: @fpext
176176
func.func @fpext_vector(%arg0 : vector<2xf16>, %arg1 : vector<2xf32>) {
177-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf16> to vector<2xf32>
177+
// CHECK-NEXT: = llvm.fpext {{.*}} : vector<2xf16> to vector<2xf32>
178178
%0 = arith.extf %arg0: vector<2xf16> to vector<2xf32>
179-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf16> to vector<2xf64>
179+
// CHECK-NEXT: = llvm.fpext {{.*}} : vector<2xf16> to vector<2xf64>
180180
%1 = arith.extf %arg0: vector<2xf16> to vector<2xf64>
181-
// CHECK-NEXT: = llvm.fpext {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf32> to vector<2xf64>
181+
// CHECK-NEXT: = llvm.fpext {{.*}} : vector<2xf32> to vector<2xf64>
182182
%2 = arith.extf %arg1: vector<2xf32> to vector<2xf64>
183183
return
184184
}
@@ -268,38 +268,38 @@ func.func @uitofp_vector(%arg0 : vector<2xi16>, %arg1 : vector<2xi32>, %arg2 : v
268268
// Checking conversion of integer types to floating point.
269269
// CHECK-LABEL: @fptrunc
270270
func.func @fptrunc(%arg0 : f32, %arg1 : f64) {
271-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : f32 to f16
271+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : f32 to f16
272272
%0 = arith.truncf %arg0: f32 to f16
273-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : f64 to f16
273+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : f64 to f16
274274
%1 = arith.truncf %arg1: f64 to f16
275-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : f64 to f32
275+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : f64 to f32
276276
%2 = arith.truncf %arg1: f64 to f32
277277
return
278278
}
279279

280280
// Checking conversion of integer types to floating point.
281281
// CHECK-LABEL: @fptrunc
282282
func.func @fptrunc_vector(%arg0 : vector<2xf32>, %arg1 : vector<2xf64>) {
283-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf32> to vector<2xf16>
283+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : vector<2xf32> to vector<2xf16>
284284
%0 = arith.truncf %arg0: vector<2xf32> to vector<2xf16>
285-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf64> to vector<2xf16>
285+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : vector<2xf64> to vector<2xf16>
286286
%1 = arith.truncf %arg1: vector<2xf64> to vector<2xf16>
287-
// CHECK-NEXT: = llvm.fptrunc {{.*}} {fastmath = #arith.fastmath<none>} : vector<2xf64> to vector<2xf32>
287+
// CHECK-NEXT: = llvm.fptrunc {{.*}} : vector<2xf64> to vector<2xf32>
288288
%2 = arith.truncf %arg1: vector<2xf64> to vector<2xf32>
289289
return
290290
}
291291

292292
// CHECK-LABEL: experimental_constrained_fptrunc
293293
func.func @experimental_constrained_fptrunc(%arg0 : f64) {
294-
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} tonearest ignore {fastmath = #arith.fastmath<none>} : f64 to f32
294+
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} tonearest ignore : f64 to f32
295295
%0 = arith.truncf %arg0 to_nearest_even : f64 to f32
296-
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} downward ignore {fastmath = #arith.fastmath<none>} : f64 to f32
296+
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} downward ignore : f64 to f32
297297
%1 = arith.truncf %arg0 downward : f64 to f32
298-
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} upward ignore {fastmath = #arith.fastmath<none>} : f64 to f32
298+
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} upward ignore : f64 to f32
299299
%2 = arith.truncf %arg0 upward : f64 to f32
300-
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} towardzero ignore {fastmath = #arith.fastmath<none>} : f64 to f32
300+
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} towardzero ignore : f64 to f32
301301
%3 = arith.truncf %arg0 toward_zero : f64 to f32
302-
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} tonearestaway ignore {fastmath = #arith.fastmath<none>} : f64 to f32
302+
// CHECK-NEXT: = llvm.intr.experimental.constrained.fptrunc {{.*}} tonearestaway ignore : f64 to f32
303303
%4 = arith.truncf %arg0 to_nearest_away : f64 to f32
304304
return
305305
}

0 commit comments

Comments
 (0)