aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Leyonberg <jan_sjodin@yahoo.com>2024-04-19 15:50:55 -0400
committerGitHub <noreply@github.com>2024-04-19 15:50:55 -0400
commit0c455ee34823cb991a35e33ff020bb7cc4e44c8a (patch)
tree762b24400af91ab653aa1e1ee9e31a1c634e1b7f
parentc32712d1763d74329b42c1cd68a24d4c0075b596 (diff)
downloadllvm-0c455ee34823cb991a35e33ff020bb7cc4e44c8a.zip
llvm-0c455ee34823cb991a35e33ff020bb7cc4e44c8a.tar.gz
llvm-0c455ee34823cb991a35e33ff020bb7cc4e44c8a.tar.bz2
[flang][OpenMP] Use maxnum/minnum for lowering of max/min reduction operators (#89258)
This patch changes the lowering of max and min to be lowered to arith::MaxNumFop and arith::MinNumFOp instead of using arith::MaximumFOp and arith::MinimumFOp. The arith::MaximumFOp and arith::MinimumFOp map to the corresponding intrinsics llvm.maximum.* and llvm.minimum.* intrinsics which conform to the semantics specified in the draft of IEEE 754-2019, which is not supported by all hardware. Instead using arith::MaximumFOp and arith::MinimumFOp will allow code generation for more targets and match the code generated by clang OpenMP. fixes #87955
-rw-r--r--flang/lib/Lower/OpenMP/ReductionProcessor.cpp4
-rw-r--r--flang/test/Lower/OpenMP/FIR/wsloop-reduction-max-byref.f902
-rw-r--r--flang/test/Lower/OpenMP/FIR/wsloop-reduction-max.f902
-rw-r--r--flang/test/Lower/OpenMP/FIR/wsloop-reduction-min-byref.f902
-rw-r--r--flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f902
-rw-r--r--flang/test/Lower/OpenMP/wsloop-reduction-max-byref.f902
-rw-r--r--flang/test/Lower/OpenMP/wsloop-reduction-max.f902
-rw-r--r--flang/test/Lower/OpenMP/wsloop-reduction-min-byref.f902
-rw-r--r--flang/test/Lower/OpenMP/wsloop-reduction-min.f902
9 files changed, 10 insertions, 10 deletions
diff --git a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
index 6a91ee4..9f8352a 100644
--- a/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/ReductionProcessor.cpp
@@ -220,12 +220,12 @@ mlir::Value ReductionProcessor::createScalarCombiner(
switch (redId) {
case ReductionIdentifier::MAX:
reductionOp =
- getReductionOperation<mlir::arith::MaximumFOp, mlir::arith::MaxSIOp>(
+ getReductionOperation<mlir::arith::MaxNumFOp, mlir::arith::MaxSIOp>(
builder, type, loc, op1, op2);
break;
case ReductionIdentifier::MIN:
reductionOp =
- getReductionOperation<mlir::arith::MinimumFOp, mlir::arith::MinSIOp>(
+ getReductionOperation<mlir::arith::MinNumFOp, mlir::arith::MinSIOp>(
builder, type, loc, op1, op2);
break;
case ReductionIdentifier::IOR:
diff --git a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max-byref.f90 b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max-byref.f90
index f0979ab..80b720e 100644
--- a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max-byref.f90
+++ b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max-byref.f90
@@ -11,7 +11,7 @@
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
!CHECK: %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>
-!CHECK: %[[RES:.*]] = arith.maximumf %[[LD0]], %[[LD1]] {{.*}}: f32
+!CHECK: %[[RES:.*]] = arith.maxnumf %[[LD0]], %[[LD1]] {{.*}}: f32
!CHECK: fir.store %[[RES]] to %[[ARG0]] : !fir.ref<f32>
!CHECK: omp.yield(%[[ARG0]] : !fir.ref<f32>)
diff --git a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max.f90 b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max.f90
index 996296c..c3b821e 100644
--- a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max.f90
+++ b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-max.f90
@@ -6,7 +6,7 @@
!CHECK: omp.yield(%[[MINIMUM_VAL_F]] : f32)
!CHECK: combiner
!CHECK: ^bb0(%[[ARG0_F:.*]]: f32, %[[ARG1_F:.*]]: f32):
-!CHECK: %[[COMB_VAL_F:.*]] = arith.maximumf %[[ARG0_F]], %[[ARG1_F]] {{.*}}: f32
+!CHECK: %[[COMB_VAL_F:.*]] = arith.maxnumf %[[ARG0_F]], %[[ARG1_F]] {{.*}}: f32
!CHECK: omp.yield(%[[COMB_VAL_F]] : f32)
!CHECK: omp.declare_reduction @[[MAX_DECLARE_I:.*]] : i32 init {
diff --git a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min-byref.f90 b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min-byref.f90
index 24aa8e4..b284f8e5 100644
--- a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min-byref.f90
+++ b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min-byref.f90
@@ -11,7 +11,7 @@
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
!CHECK: %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>
-!CHECK: %[[RES:.*]] = arith.minimumf %[[LD0]], %[[LD1]] {{.*}}: f32
+!CHECK: %[[RES:.*]] = arith.minnumf %[[LD0]], %[[LD1]] {{.*}}: f32
!CHECK: fir.store %[[RES]] to %[[ARG0]] : !fir.ref<f32>
!CHECK: omp.yield(%[[ARG0]] : !fir.ref<f32>)
diff --git a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f90 b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f90
index 268f51c..ab33e18 100644
--- a/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f90
+++ b/flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f90
@@ -6,7 +6,7 @@
!CHECK: omp.yield(%[[MAXIMUM_VAL_F]] : f32)
!CHECK: combiner
!CHECK: ^bb0(%[[ARG0_F:.*]]: f32, %[[ARG1_F:.*]]: f32):
-!CHECK: %[[COMB_VAL_F:.*]] = arith.minimumf %[[ARG0_F]], %[[ARG1_F]] {{.*}}: f32
+!CHECK: %[[COMB_VAL_F:.*]] = arith.minnumf %[[ARG0_F]], %[[ARG1_F]] {{.*}}: f32
!CHECK: omp.yield(%[[COMB_VAL_F]] : f32)
!CHECK: omp.declare_reduction @[[MIN_DECLARE_I:.*]] : i32 init {
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-max-byref.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-max-byref.f90
index ee562bb..2f6921e 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-max-byref.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-max-byref.f90
@@ -13,7 +13,7 @@
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
!CHECK: %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>
-!CHECK: %[[RES:.*]] = arith.maximumf %[[LD0]], %[[LD1]] {{.*}}: f32
+!CHECK: %[[RES:.*]] = arith.maxnumf %[[LD0]], %[[LD1]] {{.*}}: f32
!CHECK: fir.store %[[RES]] to %[[ARG0]] : !fir.ref<f32>
!CHECK: omp.yield(%[[ARG0]] : !fir.ref<f32>)
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
index 6f11f0e..c9cf5cb 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
@@ -10,7 +10,7 @@
! CHECK-LABEL: } combiner {
! CHECK: ^bb0(%[[VAL_0:.*]]: f32, %[[VAL_1:.*]]: f32):
-! CHECK: %[[VAL_2:.*]] = arith.maximumf %[[VAL_0]], %[[VAL_1]] fastmath<contract> : f32
+! CHECK: %[[VAL_2:.*]] = arith.maxnumf %[[VAL_0]], %[[VAL_1]] fastmath<contract> : f32
! CHECK: omp.yield(%[[VAL_2]] : f32)
! CHECK: }
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-min-byref.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-min-byref.f90
index c037211..84a376b 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-min-byref.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-min-byref.f90
@@ -13,7 +13,7 @@
!CHECK: ^bb0(%[[ARG0:.*]]: !fir.ref<f32>, %[[ARG1:.*]]: !fir.ref<f32>):
!CHECK: %[[LD0:.*]] = fir.load %[[ARG0]] : !fir.ref<f32>
!CHECK: %[[LD1:.*]] = fir.load %[[ARG1]] : !fir.ref<f32>
-!CHECK: %[[RES:.*]] = arith.minimumf %[[LD0]], %[[LD1]] {{.*}}: f32
+!CHECK: %[[RES:.*]] = arith.minnumf %[[LD0]], %[[LD1]] {{.*}}: f32
!CHECK: fir.store %[[RES]] to %[[ARG0]] : !fir.ref<f32>
!CHECK: omp.yield(%[[ARG0]] : !fir.ref<f32>)
diff --git a/flang/test/Lower/OpenMP/wsloop-reduction-min.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-min.f90
index 2c694f8..3ba279a 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-min.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-min.f90
@@ -10,7 +10,7 @@
! CHECK-LABEL: } combiner {
! CHECK: ^bb0(%[[VAL_0:.*]]: f32, %[[VAL_1:.*]]: f32):
-! CHECK: %[[VAL_2:.*]] = arith.minimumf %[[VAL_0]], %[[VAL_1]] fastmath<contract> : f32
+! CHECK: %[[VAL_2:.*]] = arith.minnumf %[[VAL_0]], %[[VAL_1]] fastmath<contract> : f32
! CHECK: omp.yield(%[[VAL_2]] : f32)
! CHECK: }