Skip to content

Commit 9308d66

Browse files
authored
[Flang] Correct initial limit value in float min/maxloc reductions. (llvm#81260)
I was looking through to check whether Nan was being handled correctly, and couldn't work out why simple cases were behaving differently than they should. It turns out the initial limit values was backwards for minloc/maxloc reductions in general. This fixes that, introduced in llvm#79469.
1 parent 2a4a255 commit 9308d66

File tree

3 files changed

+3
-1
lines changed

3 files changed

+3
-1
lines changed

flang/lib/Optimizer/HLFIR/Transforms/OptimizedBufferization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
854854
const llvm::fltSemantics &sem = ty.getFloatSemantics();
855855
return builder.createRealConstant(
856856
loc, elementType,
857-
llvm::APFloat::getLargest(sem, /*Negative=*/!isMax));
857+
llvm::APFloat::getLargest(sem, /*Negative=*/isMax));
858858
}
859859
unsigned bits = elementType.getIntOrFloatBitWidth();
860860
int64_t limitInt =

flang/test/HLFIR/maxloc-elemental.fir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
110110
return
111111
}
112112
// CHECK-LABEL: _QPtest_float
113+
// CHECK: %cst = arith.constant -3.40282347E+38 : f32
113114
// CHECK: %[[V11:.*]] = fir.do_loop %arg3 = %c0 to %[[V10:.*]] step %c1 iter_args(%arg4 = %cst) -> (f32) {
114115
// CHECK-NEXT: %[[V14:.*]] = arith.addi %arg3, %c1 : index
115116
// CHECK-NEXT: %[[V15:.*]] = hlfir.designate %[[V1:.*]]#0 (%[[V14]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>

flang/test/HLFIR/minloc-elemental.fir

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
295295
return
296296
}
297297
// CHECK-LABEL: _QPtest_float
298+
// CHECK: %cst = arith.constant 3.40282347E+38 : f32
298299
// CHECK: %[[V11:.*]] = fir.do_loop %arg3 = %c0 to %[[V10:.*]] step %c1 iter_args(%arg4 = %cst) -> (f32) {
299300
// CHECK-NEXT: %[[V14:.*]] = arith.addi %arg3, %c1 : index
300301
// CHECK-NEXT: %[[V15:.*]] = hlfir.designate %[[V1:.*]]#0 (%[[V14]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>

0 commit comments

Comments
 (0)