Skip to content

Commit 595cc96

Browse files
[flang] Propagate fast-math flags in target-rewrite (#135723)
TargetRewritePass was dropping fast-math flags. Add the flags to the new call ops and update tests.
1 parent 9a6c001 commit 595cc96

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

Diff for: flang/lib/Optimizer/CodeGen/TargetRewrite.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> {
542542
mlir::TypeRange{newInTypes}.drop_front(dropFront), newResTys));
543543
newCall = rewriter->create<fir::CallOp>(loc, newResTys, newOpers);
544544
}
545+
newCall.setFastmathAttr(callOp.getFastmathAttr());
545546
// Always set ABI argument attributes on call operations, even when
546547
// direct, as required by
547548
// https://llvm.org/docs/LangRef.html#parameter-attributes.

Diff for: flang/test/Fir/CUDA/cuda-target-rewrite.mlir

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ gpu.module @testmod {
1414
}
1515

1616
// CHECK-LABEL: gpu.func @_QPvcpowdk
17-
// CHECK: %{{.*}} = fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}, %{{.*}}) : (f64, f64, i64) -> tuple<f64, f64>
17+
// CHECK: %{{.*}} = fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}, %{{.*}}) fastmath<contract> : (f64, f64, i64) -> tuple<f64, f64>
1818
// CHECK: func.func private @_FortranAzpowk(f64, f64, i64) -> tuple<f64, f64> attributes {fir.bindc_name = "_FortranAzpowk", fir.runtime}
1919
}
2020

Diff for: flang/test/Fir/target-rewrite-fmfs.fir

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: fir-opt --target-rewrite %s | FileCheck %s
2+
3+
// CHECK-LABEL: func.func @libm_preserves_fmfs
4+
func.func @libm_preserves_fmfs(%arg0 : complex<f32>) -> complex<f32> {
5+
%0 = fir.call @csin(%arg0) fastmath<contract> : (complex<f32>) -> complex<f32>
6+
// CHECK: fir.call @csin(%{{.+}}) fastmath<contract>
7+
return %0 : complex<f32>
8+
}

Diff for: flang/test/Fir/target-rewrite-selective.fir

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
// r = test2(value)
2222
// end function
2323

24-
// CMPLXOFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32>
25-
// CMPLXOFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1>
24+
// CMPLXOFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32>
25+
// CMPLXOFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1>
2626
// CMPLXOFF-DAG: func.func private @_QPtest1(!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32>
2727
// CMPLXOFF-DAG: func.func private @_QPtest2(!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1>
2828

29-
// CHAROFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}) : (!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32>
30-
// CHAROFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1>
29+
// CHAROFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}) fastmath<contract> : (!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32>
30+
// CHAROFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1>
3131
// CHAROFF-DAG: func.func private @_QPtest1(!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32>
3232
// CHAROFF-DAG: func.func private @_QPtest2(!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1>
3333

0 commit comments

Comments
 (0)