Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
// if mask is a logical scalar, we can check its value before the main loop
// and either ignore the fact it is there or exit early.
if (maskRank == 0) {
mlir::Type logical = builder.getI1Type();
mlir::Type i1Type = builder.getI1Type();
mlir::Type logical = maskElemType;
mlir::IndexType idxTy = builder.getIndexType();

fir::SequenceType::Shape singleElement(1, 1);
Expand All @@ -834,8 +835,9 @@ static void genRuntimeMinMaxlocBody(fir::FirOpBuilder &builder,
mlir::Value condAddr =
builder.create<fir::CoordinateOp>(loc, logicalRefTy, array, indx);
mlir::Value cond = builder.create<fir::LoadOp>(loc, condAddr);
mlir::Value condI1 = builder.create<fir::ConvertOp>(loc, i1Type, cond);

fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, cond,
fir::IfOp ifOp = builder.create<fir::IfOp>(loc, elementType, condI1,
/*withElseRegion=*/true);

builder.setInsertionPointToStart(&ifOp.getElseRegion().front());
Expand Down
14 changes: 8 additions & 6 deletions flang/test/Transforms/simplifyintrinsics.fir
Original file line number Diff line number Diff line change
Expand Up @@ -1996,10 +1996,11 @@ func.func @_QPtestminloc_works1d_scalarmask_f64(%arg0: !fir.ref<!fir.array<10xf6
// CHECK: %[[OUTARR_IDX0:.*]] = arith.constant 0 : index
// CHECK: %[[OUTARR_ITEM0:.*]] = fir.coordinate_of %[[BOX_OUTARR]], %[[OUTARR_IDX0]] : (!fir.box<!fir.heap<!fir.array<1xi32>>>, index) -> !fir.ref<i32>
// CHECK: fir.store %[[INIT_OUT_IDX]] to %[[OUTARR_ITEM0]] : !fir.ref<i32>
// CHECK: %[[BOX_MASK:.*]] = fir.convert %[[BOX_MASK_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<1xi1>>
// CHECK: %[[BOX_MASK:.*]] = fir.convert %[[BOX_MASK_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<1x!fir.logical<4>>>
// CHECK: %[[MASK_IDX0:.*]] = arith.constant 0 : index
// CHECK: %[[MASK_ITEM:.*]] = fir.coordinate_of %[[BOX_MASK]], %[[MASK_IDX0]] : (!fir.box<!fir.array<1xi1>>, index) -> !fir.ref<i1>
// CHECK: %[[MASK:.*]] = fir.load %[[MASK_ITEM]] : !fir.ref<i1>
// CHECK: %[[MASK_ITEM:.*]] = fir.coordinate_of %[[BOX_MASK]], %[[MASK_IDX0]] : (!fir.box<!fir.array<1x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>>
// CHECK: %[[MASK_LOGICAL:.*]] = fir.load %[[MASK_ITEM]] : !fir.ref<!fir.logical<4>>
// CHECK: %[[MASK:.*]] = fir.convert %[[MASK_LOGICAL]] : (!fir.logical<4>) -> i1
// CHECK: %[[INIT_RES:.*]] = fir.if %[[MASK]] -> (f64) {
// CHECK: %[[C_INDEX0:.*]] = arith.constant 0 : index
// CHECK: %[[BOX_INARR:.*]] = fir.convert %[[BOX_INARR_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<?xf64>>
Expand Down Expand Up @@ -2573,10 +2574,11 @@ func.func @_QPtestmaxloc_works1d_scalarmask_f64(%arg0: !fir.ref<!fir.array<10xf6
// CHECK: %[[OUTARR_IDX0:.*]] = arith.constant 0 : index
// CHECK: %[[OUTARR_ITEM0:.*]] = fir.coordinate_of %[[BOX_OUTARR]], %[[OUTARR_IDX0]] : (!fir.box<!fir.heap<!fir.array<1xi32>>>, index) -> !fir.ref<i32>
// CHECK: fir.store %[[INIT_OUT_IDX]] to %[[OUTARR_ITEM0]] : !fir.ref<i32>
// CHECK: %[[BOX_MASK:.*]] = fir.convert %[[BOX_MASK_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<1xi1>>
// CHECK: %[[BOX_MASK:.*]] = fir.convert %[[BOX_MASK_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<1x!fir.logical<4>>>
// CHECK: %[[MASK_IDX0:.*]] = arith.constant 0 : index
// CHECK: %[[MASK_ITEM:.*]] = fir.coordinate_of %[[BOX_MASK]], %[[MASK_IDX0]] : (!fir.box<!fir.array<1xi1>>, index) -> !fir.ref<i1>
// CHECK: %[[MASK:.*]] = fir.load %[[MASK_ITEM]] : !fir.ref<i1>
// CHECK: %[[MASK_ITEM:.*]] = fir.coordinate_of %[[BOX_MASK]], %[[MASK_IDX0]] : (!fir.box<!fir.array<1x!fir.logical<4>>>, index) -> !fir.ref<!fir.logical<4>>
// CHECK: %[[MASK_LOGICAL:.*]] = fir.load %[[MASK_ITEM]] : !fir.ref<!fir.logical<4>>
// CHECK: %[[MASK:.*]] = fir.convert %[[MASK_LOGICAL]] : (!fir.logical<4>) -> i1
// CHECK: %[[INIT_RES:.*]] = fir.if %[[MASK]] -> (f64) {
// CHECK: %[[C_INDEX0:.*]] = arith.constant 0 : index
// CHECK: %[[BOX_INARR:.*]] = fir.convert %[[BOX_INARR_NONE]] : (!fir.box<none>) -> !fir.box<!fir.array<?xf64>>
Expand Down