Skip to content

[flang] Propagate fast-math flags to FIROpBuilder. #126316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
explicit FirOpBuilder(mlir::Operation *op, fir::KindMapping kindMap,
mlir::SymbolTable *symbolTable = nullptr)
: OpBuilder{op, /*listener=*/this}, kindMap{std::move(kindMap)},
symbolTable{symbolTable} {}
symbolTable{symbolTable} {
auto fmi = mlir::dyn_cast<mlir::arith::ArithFastMathInterface>(*op);
if (fmi) {
// Set the builder with FastMathFlags attached to the operation.
setFastMathFlags(fmi.getFastMathFlagsAttr().getValue());
}
}
explicit FirOpBuilder(mlir::OpBuilder &builder, fir::KindMapping kindMap,
mlir::SymbolTable *symbolTable = nullptr)
: OpBuilder(builder), OpBuilder::Listener(), kindMap{std::move(kindMap)},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,7 @@ class ReductionConversion : public mlir::OpRewritePattern<Op> {
llvm_unreachable("unsupported type");
};

fir::KindMapping kindMap =
fir::getKindMapping(op->template getParentOfType<mlir::ModuleOp>());
fir::FirOpBuilder builder{op, kindMap};
fir::FirOpBuilder builder{rewriter, op.getOperation()};

mlir::Value init;
GenBodyFn genBodyFn;
Expand Down
6 changes: 3 additions & 3 deletions flang/test/HLFIR/maxval-elemental.fir
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
// CHECK-NEXT: %[[V6:.*]] = fir.do_loop %arg1 = %c1 to %c4 step %c1 iter_args(%arg2 = %cst) -> (f32) {
// CHECK-NEXT: %[[V7:.*]] = hlfir.designate %[[V5]] (%arg1) : (!fir.box<!fir.array<4xf32>>, index) -> !fir.ref<f32>
// CHECK-NEXT: %[[V8:.*]] = fir.load %[[V7]] : !fir.ref<f32>
// CHECK-NEXT: %[[V9:.*]] = arith.cmpf ogt, %[[V8]], %arg2 : f32
// CHECK-NEXT: %[[V10:.*]] = arith.cmpf une, %arg2, %arg2 : f32
// CHECK-NEXT: %[[V11:.*]] = arith.cmpf oeq, %[[V8]], %[[V8]] : f32
// CHECK-NEXT: %[[V9:.*]] = arith.cmpf ogt, %[[V8]], %arg2 fastmath<contract> : f32
// CHECK-NEXT: %[[V10:.*]] = arith.cmpf une, %arg2, %arg2 fastmath<contract> : f32
// CHECK-NEXT: %[[V11:.*]] = arith.cmpf oeq, %[[V8]], %[[V8]] fastmath<contract> : f32
// CHECK-NEXT: %[[V12:.*]] = arith.andi %[[V10]], %[[V11]] : i1
// CHECK-NEXT: %[[V13:.*]] = arith.ori %[[V9]], %[[V12]] : i1
// CHECK-NEXT: %[[V14:.*]] = arith.select %[[V13]], %[[V8]], %arg2 : f32
Expand Down
6 changes: 3 additions & 3 deletions flang/test/HLFIR/minval-elemental.fir
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
// CHECK-NEXT: %[[V6:.*]] = fir.do_loop %arg1 = %c1 to %c4 step %c1 iter_args(%arg2 = %cst) -> (f32) {
// CHECK-NEXT: %[[V7:.*]] = hlfir.designate %[[V5]] (%arg1) : (!fir.box<!fir.array<4xf32>>, index) -> !fir.ref<f32>
// CHECK-NEXT: %[[V8:.*]] = fir.load %[[V7]] : !fir.ref<f32>
// CHECK-NEXT: %[[V9:.*]] = arith.cmpf olt, %[[V8]], %arg2 : f32
// CHECK-NEXT: %[[V10:.*]] = arith.cmpf une, %arg2, %arg2 : f32
// CHECK-NEXT: %[[V11:.*]] = arith.cmpf oeq, %[[V8]], %[[V8]] : f32
// CHECK-NEXT: %[[V9:.*]] = arith.cmpf olt, %[[V8]], %arg2 fastmath<contract> : f32
// CHECK-NEXT: %[[V10:.*]] = arith.cmpf une, %arg2, %arg2 fastmath<contract> : f32
// CHECK-NEXT: %[[V11:.*]] = arith.cmpf oeq, %[[V8]], %[[V8]] fastmath<contract> : f32
// CHECK-NEXT: %[[V12:.*]] = arith.andi %[[V10]], %[[V11]] : i1
// CHECK-NEXT: %[[V13:.*]] = arith.ori %[[V9]], %[[V12]] : i1
// CHECK-NEXT: %[[V14:.*]] = arith.select %[[V13]], %[[V8]], %arg2 : f32
Expand Down