Skip to content

Commit

Permalink
[Flang] Correct initial limit value in float min/maxloc reductions. (#…
Browse files Browse the repository at this point in the history
…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
#79469.
  • Loading branch information
davemgreen committed Feb 10, 2024
1 parent 2a4a255 commit 9308d66
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ class MinMaxlocElementalConversion : public mlir::OpRewritePattern<Op> {
const llvm::fltSemantics &sem = ty.getFloatSemantics();
return builder.createRealConstant(
loc, elementType,
llvm::APFloat::getLargest(sem, /*Negative=*/!isMax));
llvm::APFloat::getLargest(sem, /*Negative=*/isMax));
}
unsigned bits = elementType.getIntOrFloatBitWidth();
int64_t limitInt =
Expand Down
1 change: 1 addition & 0 deletions flang/test/HLFIR/maxloc-elemental.fir
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
return
}
// CHECK-LABEL: _QPtest_float
// CHECK: %cst = arith.constant -3.40282347E+38 : f32
// CHECK: %[[V11:.*]] = fir.do_loop %arg3 = %c0 to %[[V10:.*]] step %c1 iter_args(%arg4 = %cst) -> (f32) {
// CHECK-NEXT: %[[V14:.*]] = arith.addi %arg3, %c1 : index
// CHECK-NEXT: %[[V15:.*]] = hlfir.designate %[[V1:.*]]#0 (%[[V14]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
Expand Down
1 change: 1 addition & 0 deletions flang/test/HLFIR/minloc-elemental.fir
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ func.func @_QPtest_float(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a
return
}
// CHECK-LABEL: _QPtest_float
// CHECK: %cst = arith.constant 3.40282347E+38 : f32
// CHECK: %[[V11:.*]] = fir.do_loop %arg3 = %c0 to %[[V10:.*]] step %c1 iter_args(%arg4 = %cst) -> (f32) {
// CHECK-NEXT: %[[V14:.*]] = arith.addi %arg3, %c1 : index
// CHECK-NEXT: %[[V15:.*]] = hlfir.designate %[[V1:.*]]#0 (%[[V14]]) : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
Expand Down

0 comments on commit 9308d66

Please sign in to comment.