Skip to content

Commit bffea5c

Browse files
committed
EOSHIFT Lowering - address review comments
- boundary should be passed as address - no need to codegen everything in the absence of a boundary argument, use a fir::AbsentOp with a generic NoneType Box instead - update unittest
1 parent 20b933b commit bffea5c

File tree

2 files changed

+10
-67
lines changed

2 files changed

+10
-67
lines changed

flang/lib/Lower/IntrinsicCall.cpp

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static constexpr IntrinsicHandler handlers[]{
686686
&I::genEoshift,
687687
{{{"array", asAddr},
688688
{"shift", asAddr},
689-
{"boundary", asValue},
689+
{"boundary", asAddr},
690690
{"dim", asValue}}},
691691
/*isElemental=*/false},
692692
{"exponent", &I::genExponent},
@@ -2150,47 +2150,10 @@ IntrinsicLibrary::genEoshift(mlir::Type resultType,
21502150
fir::factory::getMutableIRBox(builder, loc, resultMutableBox);
21512151

21522152
// Handle optional BOUNDARY argument
2153-
mlir::Type arrayEleTy = arrayBox.getEleTy();
2154-
mlir::Value boundary = nullptr;
2155-
2156-
if (isAbsent(args[2])) {
2157-
if (arrayEleTy.isa<mlir::IntegerType>() ||
2158-
arrayEleTy.isa<mlir::FloatType>() ||
2159-
arrayEleTy.isa<fir::LogicalType>()) {
2160-
// fill in with appropriate number of 0 or .false.
2161-
auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
2162-
auto temp = builder.createTemporary(loc, arrayEleTy);
2163-
auto cast = builder.createConvert(loc, arrayEleTy, zero);
2164-
builder.create<fir::StoreOp>(loc, cast, temp);
2165-
boundary = builder.createBox(loc, temp);
2166-
} else if (arrayEleTy.isa<fir::CharacterType>()) {
2167-
// fill in with appropriate number of blanks
2168-
fir::factory::CharacterExprHelper helper{builder, loc};
2169-
fir::CharacterType charTy = helper.getCharacterType(arrayEleTy);
2170-
fir::CharBoxValue temp =
2171-
helper.createCharacterTemp(arrayEleTy, charTy.getLen());
2172-
auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
2173-
auto len = builder.createIntegerConstant(
2174-
loc, builder.getCharacterLengthType(), charTy.getLen());
2175-
2176-
helper.createPadding(temp, zero, len);
2177-
2178-
boundary = builder.createBox(loc, temp);
2179-
} else
2180-
fir::emitFatalError(loc, "bad type for EOSHIFT");
2181-
} else {
2182-
if (arrayEleTy.isa<mlir::IntegerType>() ||
2183-
arrayEleTy.isa<mlir::FloatType>() ||
2184-
arrayEleTy.isa<fir::LogicalType>()) {
2185-
auto temp = builder.createTemporary(loc, arrayEleTy);
2186-
auto cast = builder.createConvert(loc, arrayEleTy, fir::getBase(args[2]));
2187-
builder.create<fir::StoreOp>(loc, cast, temp);
2188-
boundary = builder.createBox(loc, temp);
2189-
} else if (arrayEleTy.isa<fir::CharacterType>())
2190-
boundary = builder.createBox(loc, args[2]);
2191-
else
2192-
fir::emitFatalError(loc, "bad type for EOSHIFT");
2193-
}
2153+
auto boundary = isAbsent(args[2])
2154+
? builder.create<fir::AbsentOp>(
2155+
loc, fir::BoxType::get(builder.getNoneType()))
2156+
: builder.createBox(loc, args[2]);
21942157

21952158
if (arrayRank == 1) {
21962159
// Vector case

flang/test/Lower/intrinsic-procedures/eoshift.f90

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,22 @@
44
subroutine eoshift_test1(arr, shift)
55
logical, dimension(3) :: arr, res
66
integer :: shift
7-
! CHECK: %[[boundAlloc:.*]] = fir.alloca !fir.logical<4> {uniq_name = ""}
87
! CHECK: %[[resBox:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>> {uniq_name = ""}
98
! CHECK: %[[res:.*]] = fir.alloca !fir.array<3x!fir.logical<4>> {bindc_name = "res", uniq_name = "_QFeoshift_test1Eres"}
109
! CHECK: %[[resLoad:.*]] = fir.array_load %[[res]]({{.*}}) : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.array<3x!fir.logical<4>>
1110
! CHECK: %[[arr:.*]] = fir.embox %arg0({{.*}}) : (!fir.ref<!fir.array<3x!fir.logical<4>>>, !fir.shape<1>) -> !fir.box<!fir.array<3x!fir.logical<4>>>
1211
! CHECK: %[[bits:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.logical<4>>>
1312
! CHECK: %[[init:.*]] = fir.embox %[[bits]]({{.*}}) : (!fir.heap<!fir.array<?x!fir.logical<4>>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>
1413
! CHECK: fir.store %[[init]] to %[[resBox]] : !fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>>
15-
! CHECK: %[[zero:.*]] = constant 0 : index
16-
! CHECK: %[[false:.*]] = fir.convert %[[zero]] : (index) -> !fir.logical<4>
17-
! CHECK: fir.store %[[false]] to %[[boundAlloc]] : !fir.ref<!fir.logical<4>>
18-
! CHECK: %[[boundBox:.*]] = fir.embox %[[boundAlloc]] : (!fir.ref<!fir.logical<4>>) -> !fir.box<!fir.logical<4>>
14+
! CHECK: %[[boundBox:.*]] = fir.absent !fir.box<none>
1915
! CHECK: %[[shift:.*]] = fir.load %arg1 : !fir.ref<i32>
2016

2117
res = eoshift(arr, shift)
2218

2319
! CHECK: %[[resIRBox:.*]] = fir.convert %[[resBox]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x!fir.logical<4>>>>>) -> !fir.ref<!fir.box<none>>
2420
! CHECK: %[[arrBox:.*]] = fir.convert %[[arr]] : (!fir.box<!fir.array<3x!fir.logical<4>>>) -> !fir.box<none>
2521
! CHECK: %[[shiftBox:.*]] = fir.convert %[[shift]] : (i32) -> i64
26-
! CHECK: %[[boundBoxNone:.*]] = fir.convert %[[boundBox]] : (!fir.box<!fir.logical<4>>) -> !fir.box<none>
27-
! CHECK: %[[tmp:.*]] = fir.call @_FortranAEoshiftVector(%[[resIRBox]], %[[arrBox]], %[[shiftBox]], %[[boundBoxNone]], {{.*}}, {{.*}}) : (!fir.ref<!fir.box<none>>, !fir.box<none>, i64, !fir.box<none>, !fir.ref<i8>, i32) -> none
22+
! CHECK: %[[tmp:.*]] = fir.call @_FortranAEoshiftVector(%[[resIRBox]], %[[arrBox]], %[[shiftBox]], %[[boundBox]], {{.*}}, {{.*}}) : (!fir.ref<!fir.box<none>>, !fir.box<none>, i64, !fir.box<none>, !fir.ref<i8>, i32) -> none
2823
! CHECK: fir.array_merge_store %[[resLoad]], {{.*}} to %[[res]] : !fir.array<3x!fir.logical<4>>, !fir.array<3x!fir.logical<4>>, !fir.ref<!fir.array<3x!fir.logical<4>>>
2924
end subroutine eoshift_test1
3025

@@ -33,18 +28,15 @@ subroutine eoshift_test2(arr, shift, bound, dim)
3328
integer, dimension(3,3) :: arr, res
3429
integer, dimension(3) :: shift
3530
integer :: bound, dim
36-
! CHECK: %[[boundAlloc:.*]] = fir.alloca i32 {uniq_name = ""}
3731
! CHECK: %[[resBox:.*]] = fir.alloca !fir.box<!fir.heap<!fir.array<?x?xi32>>> {uniq_name = ""}
3832
! CHECK: %[[res:.*]] = fir.alloca !fir.array<3x3xi32> {bindc_name = "res", uniq_name = "_QFeoshift_test2Eres"}
3933
!CHECK: %[[resLoad:.*]] = fir.array_load %[[res]]({{.*}}) : (!fir.ref<!fir.array<3x3xi32>>, !fir.shape<2>) -> !fir.array<3x3xi32>
40-
! CHECK: %[[bound:.*]] = fir.load %arg2 : !fir.ref<i32>
4134
! CHECK: %[[dim:.*]] = fir.load %arg3 : !fir.ref<i32>
4235

4336
res = eoshift(arr, shift, bound, dim)
4437

4538
! CHECK: %[[arr:.*]] = fir.embox %arg0({{.*}}) : (!fir.ref<!fir.array<3x3xi32>>, !fir.shape<2>) -> !fir.box<!fir.array<3x3xi32>>
46-
! CHECK: fir.store %[[bound]] to %[[boundAlloc]] : !fir.ref<i32>
47-
! CHECK: %[[boundBox:.*]] = fir.embox %[[boundAlloc]] : (!fir.ref<i32>) -> !fir.box<i32>
39+
! CHECK: %[[boundBox:.*]] = fir.embox %arg2 : (!fir.ref<i32>) -> !fir.box<i32>
4840
! CHECK: %[[shiftBox:.*]] = fir.embox %arg1({{.*}}) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<3xi32>>
4941
! CHECK: %[[resIRBox:.*]] = fir.convert %[[resBox]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?xi32>>>>) -> !fir.ref<!fir.box<none>>
5042
! CHECK: %[[arrBox:.*]] = fir.convert %[[arr]] : (!fir.box<!fir.array<3x3xi32>>) -> !fir.box<none>
@@ -70,23 +62,11 @@ subroutine eoshift_test3(arr, shift, dim)
7062

7163
res = eoshift(arr, SHIFT=shift, DIM=dim)
7264

73-
! CHECK: %[[boundAlloc:.*]] = fir.alloca !fir.char<1,4>
74-
! CHECK: %[[zero:.*]] = constant 0 : index
75-
! CHECK: %[[len:.*]] = constant 4 : index
76-
! CHECK: %[[blankVal:.*]] = constant 32 : i8
77-
! CHECK: %[[single:.*]] = fir.undefined !fir.char<1>
78-
! CHECK: %[[blank:.*]] = fir.insert_value %[[single]], %[[blankVal]], [0 : index] : (!fir.char<1>, i8) -> !fir.char<1>
79-
! CHECK: %[[one:.*]] = constant 1 : index
80-
! CHECK: fir.do_loop %arg3 = %[[zero]] to %[[len]] step %[[one]] {
81-
! CHECK: %[[bound:.*]] = fir.convert %[[boundAlloc]] : (!fir.ref<!fir.char<1,4>>) -> !fir.ref<!fir.array<4x!fir.char<1>>>
82-
! CHECK: %[[index:.*]] = fir.coordinate_of %[[bound]], %arg3 : (!fir.ref<!fir.array<4x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
83-
!CHECK: fir.store %[[blank]] to %[[index]] : !fir.ref<!fir.char<1>>
84-
! CHECK: %[[boundBox:.*]] = fir.embox %[[boundAlloc]] : (!fir.ref<!fir.char<1,4>>) -> !fir.box<!fir.char<1,4>>
65+
! CHECK: %[[boundBox:.*]] = fir.absent !fir.box<none>
8566
! CHECK: %[[shiftBox:.*]] = fir.embox %arg1 : (!fir.ref<i32>) -> !fir.box<i32>
8667
! CHECK: %[[resIRBox:.*]] = fir.convert %[[resBox]] : (!fir.ref<!fir.box<!fir.heap<!fir.array<?x?x!fir.char<1,?>>>>>) -> !fir.ref<!fir.box<none>>
8768
! CHECK: %[[arrayBoxNone:.*]] = fir.convert %[[arrayBox]] : (!fir.box<!fir.array<3x3x!fir.char<1,4>>>) -> !fir.box<none>
8869
! CHECK: %[[shiftBoxNone:.*]] = fir.convert %[[shiftBox]] : (!fir.box<i32>) -> !fir.box<none>
89-
! CHECK: %[[boundBoxNone:.*]] = fir.convert %[[boundBox]] : (!fir.box<!fir.char<1,4>>) -> !fir.box<none>
90-
! CHECK: %[[tmp:.*]] = fir.call @_FortranAEoshift(%[[resIRBox]], %[[arrayBoxNone]], %[[shiftBoxNone]], %[[boundBoxNone]], %[[dim]], {{.*}}, {{.*}}) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.box<none>, i32, !fir.ref<i8>, i32) -> none
70+
! CHECK: %[[tmp:.*]] = fir.call @_FortranAEoshift(%[[resIRBox]], %[[arrayBoxNone]], %[[shiftBoxNone]], %[[boundBox]], %[[dim]], {{.*}}, {{.*}}) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.box<none>, !fir.box<none>, i32, !fir.ref<i8>, i32) -> none
9171
! CHECK: fir.array_merge_store %[[resLoad]], {{.*}} to %[[res]] : !fir.array<3x3x!fir.char<1,4>>, !fir.array<3x3x!fir.char<1,4>>, !fir.ref<!fir.array<3x3x!fir.char<1,4>>>
9272
end subroutine eoshift_test3

0 commit comments

Comments
 (0)