Skip to content

Commit 956cf0e

Browse files
authored
[flang][OpenMP] Fix min reduction initialization (#73102)
Initialization of reduction variable for min-reduction is set to largest negative value. As such, in presence of non-negative operands, min reduction gives incorrect output. This patch initialises min-reduction to use the maximum positive value instead, so that it can produce correct output for the entire range of real valued operands. Fixes #73101
1 parent 95828ee commit 956cf0e

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ static mlir::Value getReductionInitValue(mlir::Location loc, mlir::Type type,
754754
if (auto ty = type.dyn_cast<mlir::FloatType>()) {
755755
const llvm::fltSemantics &sem = ty.getFloatSemantics();
756756
return builder.createRealConstant(
757-
loc, type, llvm::APFloat::getSmallest(sem, /*Negative=*/true));
757+
loc, type, llvm::APFloat::getLargest(sem, /*Negative=*/false));
758758
}
759759
unsigned bits = type.getIntOrFloatBitWidth();
760760
int64_t maxInt = llvm::APInt::getSignedMaxValue(bits).getSExtValue();

flang/test/Lower/OpenMP/FIR/wsloop-reduction-min.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
33

44
!CHECK: omp.reduction.declare @[[MIN_DECLARE_F:.*]] : f32 init {
5-
!CHECK: %[[MAXIMUM_VAL_F:.*]] = arith.constant -1.401300e-45 : f32
5+
!CHECK: %[[MAXIMUM_VAL_F:.*]] = arith.constant 3.40282347E+38 : f32
66
!CHECK: omp.yield(%[[MAXIMUM_VAL_F]] : f32)
77
!CHECK: combiner
88
!CHECK: ^bb0(%[[ARG0_F:.*]]: f32, %[[ARG1_F:.*]]: f32):

flang/test/Lower/OpenMP/wsloop-reduction-min.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
! RUN: %flang_fc1 -emit-hlfir -fopenmp -o - %s 2>&1 | FileCheck %s
33

44
!CHECK: omp.reduction.declare @[[MIN_DECLARE_F:.*]] : f32 init {
5-
!CHECK: %[[MAXIMUM_VAL_F:.*]] = arith.constant -1.401300e-45 : f32
5+
!CHECK: %[[MAXIMUM_VAL_F:.*]] = arith.constant 3.40282347E+38 : f32
66
!CHECK: omp.yield(%[[MAXIMUM_VAL_F]] : f32)
77
!CHECK: combiner
88
!CHECK: ^bb0(%[[ARG0_F:.*]]: f32, %[[ARG1_F:.*]]: f32):

0 commit comments

Comments
 (0)