Skip to content

Commit 7045cb0

Browse files
committed
Fixed MINVAL/MAXVAL comparison.
The problem was detected by gfortran/minlocval_1.f90. We have to take the very first unmasked element as the current MIN/MAX value (same as flang-rt). The test was not failing before, because we used +/-INF as the init value, which was also incorrect.
1 parent 79bc4bf commit 7045cb0

File tree

3 files changed

+136
-69
lines changed

3 files changed

+136
-69
lines changed

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

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,14 @@ class MinMaxvalAsElementalConverter
651651
: public NumericReductionAsElementalConverterBase<T> {
652652
static_assert(std::is_same_v<T, hlfir::MaxvalOp> ||
653653
std::is_same_v<T, hlfir::MinvalOp>);
654+
// We have two reduction values:
655+
// * The current MIN/MAX value.
656+
// * 1 boolean indicating whether it is the first time
657+
// the mask is true.
658+
//
659+
// The boolean flag is used to replace the initial value
660+
// with the first input element even if it is NaN.
661+
static constexpr unsigned numReductions = 2;
654662
static constexpr bool isMax = std::is_same_v<T, hlfir::MaxvalOp>;
655663
using Base = NumericReductionAsElementalConverterBase<T>;
656664

@@ -668,22 +676,63 @@ class MinMaxvalAsElementalConverter
668676
}
669677

670678
virtual llvm::SmallVector<mlir::Value> genReductionInitValues() final {
671-
return {genMinMaxInitValue<isMax>(this->loc, this->builder,
672-
this->getResultElementType())};
679+
llvm::SmallVector<mlir::Value> result;
680+
fir::FirOpBuilder &builder = this->builder;
681+
mlir::Location loc = this->loc;
682+
mlir::Value init =
683+
genMinMaxInitValue<isMax>(loc, builder, this->getResultElementType());
684+
result.push_back(init);
685+
// Initial value for isFirst predicate. It is switched to false,
686+
// when the reduction update dynamically happens inside the reduction
687+
// loop.
688+
result.push_back(builder.createBool(loc, true));
689+
return result;
673690
}
691+
674692
virtual llvm::SmallVector<mlir::Value>
675693
reduceOneElement(const llvm::SmallVectorImpl<mlir::Value> &currentValue,
676694
hlfir::Entity array,
677695
mlir::ValueRange oneBasedIndices) final {
678696
this->checkReductions(currentValue);
697+
llvm::SmallVector<mlir::Value> result;
679698
fir::FirOpBuilder &builder = this->builder;
680699
mlir::Location loc = this->loc;
681700
hlfir::Entity elementValue =
682701
hlfir::loadElementAt(loc, builder, array, oneBasedIndices);
702+
mlir::Value currentMinMax = getCurrentMinMax(currentValue);
683703
mlir::Value cmp =
684-
genMinMaxComparison<isMax>(loc, builder, elementValue, currentValue[0]);
685-
return {builder.create<mlir::arith::SelectOp>(loc, cmp, elementValue,
686-
currentValue[0])};
704+
genMinMaxComparison<isMax>(loc, builder, elementValue, currentMinMax);
705+
cmp =
706+
builder.create<mlir::arith::OrIOp>(loc, cmp, getIsFirst(currentValue));
707+
mlir::Value newMinMax = builder.create<mlir::arith::SelectOp>(
708+
loc, cmp, elementValue, currentMinMax);
709+
result.push_back(newMinMax);
710+
result.push_back(builder.createBool(loc, false));
711+
return result;
712+
}
713+
714+
virtual hlfir::Entity genFinalResult(
715+
const llvm::SmallVectorImpl<mlir::Value> &reductionResults) final {
716+
this->checkReductions(reductionResults);
717+
return hlfir::Entity{getCurrentMinMax(reductionResults)};
718+
}
719+
720+
void
721+
checkReductions(const llvm::SmallVectorImpl<mlir::Value> &reductions) const {
722+
assert(reductions.size() == numReductions &&
723+
"invalid number of reductions for MINVAL/MAXVAL");
724+
}
725+
726+
mlir::Value
727+
getCurrentMinMax(const llvm::SmallVectorImpl<mlir::Value> &reductions) const {
728+
this->checkReductions(reductions);
729+
return reductions[0];
730+
}
731+
732+
mlir::Value
733+
getIsFirst(const llvm::SmallVectorImpl<mlir::Value> &reductions) const {
734+
this->checkReductions(reductions);
735+
return reductions[1];
687736
}
688737
};
689738

flang/test/HLFIR/simplify-hlfir-intrinsics-maxval.fir

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,35 @@ func.func @test_total_expr(%input: !hlfir.expr<?x?xf32>, %mask: !hlfir.expr<?x?x
77
// CHECK-LABEL: func.func @test_total_expr(
88
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !hlfir.expr<?x?xf32>,
99
// CHECK-SAME: %[[VAL_1:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !hlfir.expr<?x?x!fir.logical<4>>) -> f32 {
10+
// CHECK: %[[FALSE:.*]] = arith.constant false
1011
// CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
12+
// CHECK: %[[TRUE:.*]] = arith.constant true
1113
// CHECK: %[[VAL_3:.*]] = arith.constant -3.40282347E+38 : f32
1214
// CHECK: %[[VAL_4:.*]] = hlfir.shape_of %[[VAL_0]] : (!hlfir.expr<?x?xf32>) -> !fir.shape<2>
1315
// CHECK: %[[VAL_5:.*]] = hlfir.get_extent %[[VAL_4]] {dim = 0 : index} : (!fir.shape<2>) -> index
1416
// CHECK: %[[VAL_6:.*]] = hlfir.get_extent %[[VAL_4]] {dim = 1 : index} : (!fir.shape<2>) -> index
15-
// CHECK: %[[VAL_7:.*]] = fir.do_loop %[[VAL_8:.*]] = %[[VAL_2]] to %[[VAL_6]] step %[[VAL_2]] iter_args(%[[VAL_9:.*]] = %[[VAL_3]]) -> (f32) {
16-
// CHECK: %[[VAL_10:.*]] = fir.do_loop %[[VAL_11:.*]] = %[[VAL_2]] to %[[VAL_5]] step %[[VAL_2]] iter_args(%[[VAL_12:.*]] = %[[VAL_9]]) -> (f32) {
17+
// CHECK: %[[VAL_7:.*]]:2 = fir.do_loop %[[VAL_8:.*]] = %[[VAL_2]] to %[[VAL_6]] step %[[VAL_2]] iter_args(%[[VAL_9:.*]] = %[[VAL_3]], %[[FIRST1:.*]] = %[[TRUE]]) -> (f32, i1) {
18+
// CHECK: %[[VAL_10:.*]]:2 = fir.do_loop %[[VAL_11:.*]] = %[[VAL_2]] to %[[VAL_5]] step %[[VAL_2]] iter_args(%[[VAL_12:.*]] = %[[VAL_9]], %[[FIRST2:.*]] = %[[FIRST1]]) -> (f32, i1) {
1719
// CHECK: %[[VAL_13:.*]] = hlfir.apply %[[VAL_1]], %[[VAL_11]], %[[VAL_8]] : (!hlfir.expr<?x?x!fir.logical<4>>, index, index) -> !fir.logical<4>
1820
// CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.logical<4>) -> i1
19-
// CHECK: %[[VAL_15:.*]] = fir.if %[[VAL_14]] -> (f32) {
21+
// CHECK: %[[VAL_15:.*]]:2 = fir.if %[[VAL_14]] -> (f32, i1) {
2022
// CHECK: %[[VAL_16:.*]] = hlfir.apply %[[VAL_0]], %[[VAL_11]], %[[VAL_8]] : (!hlfir.expr<?x?xf32>, index, index) -> f32
2123
// CHECK: %[[VAL_17:.*]] = arith.cmpf ogt, %[[VAL_16]], %[[VAL_12]] fastmath<contract> : f32
2224
// CHECK: %[[VAL_18:.*]] = arith.cmpf une, %[[VAL_12]], %[[VAL_12]] fastmath<contract> : f32
2325
// CHECK: %[[VAL_19:.*]] = arith.cmpf oeq, %[[VAL_16]], %[[VAL_16]] fastmath<contract> : f32
2426
// CHECK: %[[VAL_20:.*]] = arith.andi %[[VAL_18]], %[[VAL_19]] : i1
2527
// CHECK: %[[VAL_21:.*]] = arith.ori %[[VAL_17]], %[[VAL_20]] : i1
26-
// CHECK: %[[VAL_22:.*]] = arith.select %[[VAL_21]], %[[VAL_16]], %[[VAL_12]] : f32
27-
// CHECK: fir.result %[[VAL_22]] : f32
28+
// CHECK: %[[IS_FIRST:.*]] = arith.ori %[[VAL_21]], %[[FIRST2]] : i1
29+
// CHECK: %[[VAL_22:.*]] = arith.select %[[IS_FIRST]], %[[VAL_16]], %[[VAL_12]] : f32
30+
// CHECK: fir.result %[[VAL_22]], %[[FALSE]] : f32, i1
2831
// CHECK: } else {
29-
// CHECK: fir.result %[[VAL_12]] : f32
32+
// CHECK: fir.result %[[VAL_12]], %[[FIRST2]] : f32, i1
3033
// CHECK: }
31-
// CHECK: fir.result %[[VAL_15]] : f32
34+
// CHECK: fir.result %[[VAL_15]]#0, %[[VAL_15]]#1 : f32, i1
3235
// CHECK: }
33-
// CHECK: fir.result %[[VAL_10]] : f32
36+
// CHECK: fir.result %[[VAL_10]]#0, %[[VAL_10]]#1 : f32, i1
3437
// CHECK: }
35-
// CHECK: return %[[VAL_7]] : f32
38+
// CHECK: return %[[VAL_7]]#0 : f32
3639
// CHECK: }
3740

3841
func.func @test_partial_expr(%input: !hlfir.expr<?x?xf64>, %mask: !hlfir.expr<?x?x!fir.logical<4>>) -> !hlfir.expr<?xf64> {
@@ -43,32 +46,35 @@ func.func @test_partial_expr(%input: !hlfir.expr<?x?xf64>, %mask: !hlfir.expr<?x
4346
// CHECK-LABEL: func.func @test_partial_expr(
4447
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !hlfir.expr<?x?xf64>,
4548
// CHECK-SAME: %[[VAL_1:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !hlfir.expr<?x?x!fir.logical<4>>) -> !hlfir.expr<?xf64> {
49+
// CHECK: %[[FALSE:.*]] = arith.constant false
4650
// CHECK: %[[VAL_2:.*]] = arith.constant 1 : index
51+
// CHECK: %[[TRUE:.*]] = arith.constant true
4752
// CHECK: %[[VAL_3:.*]] = arith.constant -1.7976931348623157E+308 : f64
4853
// CHECK: %[[VAL_4:.*]] = hlfir.shape_of %[[VAL_0]] : (!hlfir.expr<?x?xf64>) -> !fir.shape<2>
4954
// CHECK: %[[VAL_5:.*]] = hlfir.get_extent %[[VAL_4]] {dim = 0 : index} : (!fir.shape<2>) -> index
5055
// CHECK: %[[VAL_6:.*]] = hlfir.get_extent %[[VAL_4]] {dim = 1 : index} : (!fir.shape<2>) -> index
5156
// CHECK: %[[VAL_7:.*]] = fir.shape %[[VAL_6]] : (index) -> !fir.shape<1>
5257
// CHECK: %[[VAL_8:.*]] = hlfir.elemental %[[VAL_7]] unordered : (!fir.shape<1>) -> !hlfir.expr<?xf64> {
5358
// CHECK: ^bb0(%[[VAL_9:.*]]: index):
54-
// CHECK: %[[VAL_10:.*]] = fir.do_loop %[[VAL_11:.*]] = %[[VAL_2]] to %[[VAL_5]] step %[[VAL_2]] unordered iter_args(%[[VAL_12:.*]] = %[[VAL_3]]) -> (f64) {
59+
// CHECK: %[[VAL_10:.*]]:2 = fir.do_loop %[[VAL_11:.*]] = %[[VAL_2]] to %[[VAL_5]] step %[[VAL_2]] unordered iter_args(%[[VAL_12:.*]] = %[[VAL_3]], %[[FIRST:.*]] = %[[TRUE]]) -> (f64, i1) {
5560
// CHECK: %[[VAL_13:.*]] = hlfir.apply %[[VAL_1]], %[[VAL_11]], %[[VAL_9]] : (!hlfir.expr<?x?x!fir.logical<4>>, index, index) -> !fir.logical<4>
5661
// CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_13]] : (!fir.logical<4>) -> i1
57-
// CHECK: %[[VAL_15:.*]] = fir.if %[[VAL_14]] -> (f64) {
62+
// CHECK: %[[VAL_15:.*]]:2 = fir.if %[[VAL_14]] -> (f64, i1) {
5863
// CHECK: %[[VAL_16:.*]] = hlfir.apply %[[VAL_0]], %[[VAL_11]], %[[VAL_9]] : (!hlfir.expr<?x?xf64>, index, index) -> f64
5964
// CHECK: %[[VAL_17:.*]] = arith.cmpf ogt, %[[VAL_16]], %[[VAL_12]] fastmath<reassoc> : f64
6065
// CHECK: %[[VAL_18:.*]] = arith.cmpf une, %[[VAL_12]], %[[VAL_12]] fastmath<reassoc> : f64
6166
// CHECK: %[[VAL_19:.*]] = arith.cmpf oeq, %[[VAL_16]], %[[VAL_16]] fastmath<reassoc> : f64
6267
// CHECK: %[[VAL_20:.*]] = arith.andi %[[VAL_18]], %[[VAL_19]] : i1
6368
// CHECK: %[[VAL_21:.*]] = arith.ori %[[VAL_17]], %[[VAL_20]] : i1
64-
// CHECK: %[[VAL_22:.*]] = arith.select %[[VAL_21]], %[[VAL_16]], %[[VAL_12]] : f64
65-
// CHECK: fir.result %[[VAL_22]] : f64
69+
// CHECK: %[[IS_FIRST:.*]] = arith.ori %[[VAL_21]], %[[FIRST]] : i1
70+
// CHECK: %[[VAL_22:.*]] = arith.select %[[IS_FIRST]], %[[VAL_16]], %[[VAL_12]] : f64
71+
// CHECK: fir.result %[[VAL_22]], %[[FALSE]] : f64, i1
6672
// CHECK: } else {
67-
// CHECK: fir.result %[[VAL_12]] : f64
73+
// CHECK: fir.result %[[VAL_12]], %[[FIRST]] : f64, i1
6874
// CHECK: }
69-
// CHECK: fir.result %[[VAL_15]] : f64
75+
// CHECK: fir.result %[[VAL_15]]#0, %[[VAL_15]]#1 : f64, i1
7076
// CHECK: }
71-
// CHECK: hlfir.yield_element %[[VAL_10]] : f64
77+
// CHECK: hlfir.yield_element %[[VAL_10]]#0 : f64
7278
// CHECK: }
7379
// CHECK: return %[[VAL_8]] : !hlfir.expr<?xf64>
7480
// CHECK: }
@@ -85,12 +91,12 @@ func.func @test_total_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.ref
8591
// CHECK: %[[VAL_4:.*]] = arith.constant 0 : index
8692
// CHECK: %[[VAL_5:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_4]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
8793
// CHECK: %[[VAL_6:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_3]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
88-
// CHECK: %[[VAL_7:.*]] = fir.do_loop %[[VAL_8:.*]] = %[[VAL_3]] to %[[VAL_6]]#1 step %[[VAL_3]] unordered iter_args(%[[VAL_9:.*]] = %[[VAL_2]]) -> (f16) {
89-
// CHECK: %[[VAL_10:.*]] = fir.do_loop %[[VAL_11:.*]] = %[[VAL_3]] to %[[VAL_5]]#1 step %[[VAL_3]] unordered iter_args(%[[VAL_12:.*]] = %[[VAL_9]]) -> (f16) {
94+
// CHECK: %[[VAL_7:.*]]:2 = fir.do_loop %[[VAL_8:.*]] = %[[VAL_3]] to %[[VAL_6]]#1 step %[[VAL_3]] unordered iter_args(%[[VAL_9:.*]] = %[[VAL_2]], %[[FIRST1:.*]] = %[[TRUE]]) -> (f16, i1) {
95+
// CHECK: %[[VAL_10:.*]]:2 = fir.do_loop %[[VAL_11:.*]] = %[[VAL_3]] to %[[VAL_5]]#1 step %[[VAL_3]] unordered iter_args(%[[VAL_12:.*]] = %[[VAL_9]], %[[FIRST2:.*]] = %[[FIRST1]]) -> (f16, i1) {
9096
// CHECK: %[[VAL_13:.*]] = hlfir.designate %[[VAL_1]] (%[[VAL_11]], %[[VAL_8]]) : (!fir.ref<!fir.array<2x2x!fir.logical<1>>>, index, index) -> !fir.ref<!fir.logical<1>>
9197
// CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_13]] : !fir.ref<!fir.logical<1>>
9298
// CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_14]] : (!fir.logical<1>) -> i1
93-
// CHECK: %[[VAL_16:.*]] = fir.if %[[VAL_15]] -> (f16) {
99+
// CHECK: %[[VAL_16:.*]]:2 = fir.if %[[VAL_15]] -> (f16, i1) {
94100
// CHECK: %[[VAL_17:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_4]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
95101
// CHECK: %[[VAL_18:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_3]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
96102
// CHECK: %[[VAL_19:.*]] = arith.subi %[[VAL_17]]#0, %[[VAL_3]] : index
@@ -104,16 +110,17 @@ func.func @test_total_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.ref
104110
// CHECK: %[[VAL_27:.*]] = arith.cmpf oeq, %[[VAL_24]], %[[VAL_24]] fastmath<reassoc> : f16
105111
// CHECK: %[[VAL_28:.*]] = arith.andi %[[VAL_26]], %[[VAL_27]] : i1
106112
// CHECK: %[[VAL_29:.*]] = arith.ori %[[VAL_25]], %[[VAL_28]] : i1
107-
// CHECK: %[[VAL_30:.*]] = arith.select %[[VAL_29]], %[[VAL_24]], %[[VAL_12]] : f16
108-
// CHECK: fir.result %[[VAL_30]] : f16
113+
// CHECK: %[[IS_FIRST:.*]] = arith.ori %[[VAL_29]], %[[FIRST2]] : i1
114+
// CHECK: %[[VAL_30:.*]] = arith.select %[[IS_FIRST]], %[[VAL_24]], %[[VAL_12]] : f16
115+
// CHECK: fir.result %[[VAL_30]], %[[FALSE]] : f16, i1
109116
// CHECK: } else {
110-
// CHECK: fir.result %[[VAL_12]] : f16
117+
// CHECK: fir.result %[[VAL_12]], %[[FIRST2]] : f16, i1
111118
// CHECK: }
112-
// CHECK: fir.result %[[VAL_16]] : f16
119+
// CHECK: fir.result %[[VAL_16]]#0, %[[VAL_16]]#1 : f16, i1
113120
// CHECK: }
114-
// CHECK: fir.result %[[VAL_10]] : f16
121+
// CHECK: fir.result %[[VAL_10]]#0, %[[VAL_10]]#1 : f16, i1
115122
// CHECK: }
116-
// CHECK: return %[[VAL_7]] : f16
123+
// CHECK: return %[[VAL_7]]#0 : f16
117124
// CHECK: }
118125

119126
func.func @test_partial_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.box<!fir.array<2x2x!fir.logical<1>>>) -> !hlfir.expr<?xf16> {
@@ -124,6 +131,7 @@ func.func @test_partial_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.b
124131
// CHECK-LABEL: func.func @test_partial_var(
125132
// CHECK-SAME: %[[VAL_0:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<?x?xf16>>,
126133
// CHECK-SAME: %[[VAL_1:[0-9]+|[a-zA-Z$._-][a-zA-Z0-9$._-]*]]: !fir.box<!fir.array<2x2x!fir.logical<1>>>) -> !hlfir.expr<?xf16> {
134+
// CHECK: %[[FALSE:.*]] = arith.constant false
127135
// CHECK: %[[VAL_2:.*]] = arith.constant true
128136
// CHECK: %[[VAL_3:.*]] = arith.constant -6.550400e+04 : f16
129137
// CHECK: %[[VAL_4:.*]] = arith.constant 1 : index
@@ -134,7 +142,7 @@ func.func @test_partial_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.b
134142
// CHECK: %[[VAL_9:.*]] = fir.is_present %[[VAL_1]] : (!fir.box<!fir.array<2x2x!fir.logical<1>>>) -> i1
135143
// CHECK: %[[VAL_10:.*]] = hlfir.elemental %[[VAL_8]] unordered : (!fir.shape<1>) -> !hlfir.expr<?xf16> {
136144
// CHECK: ^bb0(%[[VAL_11:.*]]: index):
137-
// CHECK: %[[VAL_12:.*]] = fir.do_loop %[[VAL_13:.*]] = %[[VAL_4]] to %[[VAL_7]]#1 step %[[VAL_4]] unordered iter_args(%[[VAL_14:.*]] = %[[VAL_3]]) -> (f16) {
145+
// CHECK: %[[VAL_12:.*]]:2 = fir.do_loop %[[VAL_13:.*]] = %[[VAL_4]] to %[[VAL_7]]#1 step %[[VAL_4]] unordered iter_args(%[[VAL_14:.*]] = %[[VAL_3]], %[[FIRST:.*]] = %[[TRUE]]) -> (f16, i1) {
138146
// CHECK: %[[VAL_15:.*]] = fir.if %[[VAL_9]] -> (!fir.logical<1>) {
139147
// CHECK: %[[VAL_16:.*]]:3 = fir.box_dims %[[VAL_1]], %[[VAL_5]] : (!fir.box<!fir.array<2x2x!fir.logical<1>>>, index) -> (index, index, index)
140148
// CHECK: %[[VAL_17:.*]]:3 = fir.box_dims %[[VAL_1]], %[[VAL_4]] : (!fir.box<!fir.array<2x2x!fir.logical<1>>>, index) -> (index, index, index)
@@ -150,7 +158,7 @@ func.func @test_partial_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.b
150158
// CHECK: fir.result %[[VAL_24]] : !fir.logical<1>
151159
// CHECK: }
152160
// CHECK: %[[VAL_25:.*]] = fir.convert %[[VAL_15]] : (!fir.logical<1>) -> i1
153-
// CHECK: %[[VAL_26:.*]] = fir.if %[[VAL_25]] -> (f16) {
161+
// CHECK: %[[VAL_26:.*]]:2 = fir.if %[[VAL_25]] -> (f16, i1) {
154162
// CHECK: %[[VAL_27:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_5]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
155163
// CHECK: %[[VAL_28:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_4]] : (!fir.box<!fir.array<?x?xf16>>, index) -> (index, index, index)
156164
// CHECK: %[[VAL_29:.*]] = arith.subi %[[VAL_27]]#0, %[[VAL_4]] : index
@@ -164,14 +172,15 @@ func.func @test_partial_var(%input: !fir.box<!fir.array<?x?xf16>>, %mask: !fir.b
164172
// CHECK: %[[VAL_37:.*]] = arith.cmpf oeq, %[[VAL_34]], %[[VAL_34]] fastmath<reassoc> : f16
165173
// CHECK: %[[VAL_38:.*]] = arith.andi %[[VAL_36]], %[[VAL_37]] : i1
166174
// CHECK: %[[VAL_39:.*]] = arith.ori %[[VAL_35]], %[[VAL_38]] : i1
167-
// CHECK: %[[VAL_40:.*]] = arith.select %[[VAL_39]], %[[VAL_34]], %[[VAL_14]] : f16
168-
// CHECK: fir.result %[[VAL_40]] : f16
175+
// CHECK: %[[IS_FIRST:.*]] = arith.ori %[[VAL_39]], %[[FIRST]] : i1
176+
// CHECK: %[[VAL_40:.*]] = arith.select %[[IS_FIRST]], %[[VAL_34]], %[[VAL_14]] : f16
177+
// CHECK: fir.result %[[VAL_40]], %[[FALSE]] : f16, i1
169178
// CHECK: } else {
170-
// CHECK: fir.result %[[VAL_14]] : f16
179+
// CHECK: fir.result %[[VAL_14]], %[[FIRST]] : f16, i1
171180
// CHECK: }
172-
// CHECK: fir.result %[[VAL_26]] : f16
181+
// CHECK: fir.result %[[VAL_26]]#0, %[[VAL_26]]#1 : f16, i1
173182
// CHECK: }
174-
// CHECK: hlfir.yield_element %[[VAL_12]] : f16
183+
// CHECK: hlfir.yield_element %[[VAL_12]]#0 : f16
175184
// CHECK: }
176185
// CHECK: return %[[VAL_10]] : !hlfir.expr<?xf16>
177186
// CHECK: }

0 commit comments

Comments
 (0)