- Notifications
You must be signed in to change notification settings - Fork 14.9k
[flang] Propagate fast-math flags in target-rewrite #135723
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
TargetRewritePass was dropping fast-math flags. Add the flags to the new call ops and update tests.
@llvm/pr-subscribers-flang-fir-hlfir @llvm/pr-subscribers-flang-codegen Author: Asher Mancinelli (ashermancinelli) ChangesTargetRewritePass was dropping fast-math flags. Add the flags to the new call ops and update tests. Full diff: https://github.com/llvm/llvm-project/pull/135723.diff 4 Files Affected:
diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index 43ed60fc0c292..6f5e01612fc97 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -542,6 +542,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase<TargetRewrite> { mlir::TypeRange{newInTypes}.drop_front(dropFront), newResTys)); newCall = rewriter->create<fir::CallOp>(loc, newResTys, newOpers); } + newCall.setFastmathAttr(callOp.getFastmathAttr()); // Always set ABI argument attributes on call operations, even when // direct, as required by // https://llvm.org/docs/LangRef.html#parameter-attributes. diff --git a/flang/test/Fir/CUDA/cuda-target-rewrite.mlir b/flang/test/Fir/CUDA/cuda-target-rewrite.mlir index 831b5a0048008..10e8b8902aa63 100644 --- a/flang/test/Fir/CUDA/cuda-target-rewrite.mlir +++ b/flang/test/Fir/CUDA/cuda-target-rewrite.mlir @@ -14,7 +14,7 @@ gpu.module @testmod { } // CHECK-LABEL: gpu.func @_QPvcpowdk -// CHECK: %{{.*}} = fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}, %{{.*}}) : (f64, f64, i64) -> tuple<f64, f64> +// CHECK: %{{.*}} = fir.call @_FortranAzpowk(%{{.*}}, %{{.*}}, %{{.*}}) fastmath<contract> : (f64, f64, i64) -> tuple<f64, f64> // CHECK: func.func private @_FortranAzpowk(f64, f64, i64) -> tuple<f64, f64> attributes {fir.bindc_name = "_FortranAzpowk", fir.runtime} } diff --git a/flang/test/Fir/target-rewrite-fmfs.fir b/flang/test/Fir/target-rewrite-fmfs.fir new file mode 100644 index 0000000000000..e63f4acbe6671 --- /dev/null +++ b/flang/test/Fir/target-rewrite-fmfs.fir @@ -0,0 +1,8 @@ +// RUN: fir-opt --target-rewrite %s | FileCheck %s + +// CHECK-LABEL: func.func @libm_preserves_fmfs +func.func @libm_preserves_fmfs(%arg0 : complex<f32>) -> complex<f32> { + %0 = fir.call @csin(%arg0) fastmath<contract> : (complex<f32>) -> complex<f32> + // CHECK: fir.call @csin(%{{.+}}) fastmath<contract> + return %0 : complex<f32> +} diff --git a/flang/test/Fir/target-rewrite-selective.fir b/flang/test/Fir/target-rewrite-selective.fir index bfbbafdc2e2b3..eac1d35f8d24a 100644 --- a/flang/test/Fir/target-rewrite-selective.fir +++ b/flang/test/Fir/target-rewrite-selective.fir @@ -21,13 +21,13 @@ // r = test2(value) // end function -// CMPLXOFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32> -// CMPLXOFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1> +// CMPLXOFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32> +// CMPLXOFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1> // CMPLXOFF-DAG: func.func private @_QPtest1(!fir.ref<!fir.char<1,?>>, complex<f32>, i64) -> complex<f32> // CMPLXOFF-DAG: func.func private @_QPtest2(!fir.ref<!fir.char<1,10>>, index, complex<f32>) -> !fir.boxchar<1> -// CHAROFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}) : (!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32> -// CHAROFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) : (!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1> +// CHAROFF-DAG: fir.call @_QPtest1({{.*}}, {{.*}}) fastmath<contract> : (!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32> +// CHAROFF-DAG: fir.call @_QPtest2({{.*}}, {{.*}}, {{.*}}) fastmath<contract> : (!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1> // CHAROFF-DAG: func.func private @_QPtest1(!fir.boxchar<1>, !fir.vector<2:f32>) -> !fir.vector<2:f32> // CHAROFF-DAG: func.func private @_QPtest2(!fir.ref<!fir.char<1,10>>, index, !fir.vector<2:f32>) -> !fir.boxchar<1> |
vzakhari approved these changes Apr 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Asher!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
TargetRewritePass was dropping fast-math flags. Add the flags to the new call ops and update tests.