Skip to content

Commit 4c40a24

Browse files
authored
Merge pull request #238 from flang-compiler/kaph-dprod
Added an implementation for the DPROD intrinsic
2 parents 41f237a + c4e9ac2 commit 4c40a24

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

flang/lib/Lower/IntrinsicCall.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ struct IntrinsicLibrary {
208208
mlir::Value genCeiling(mlir::Type, llvm::ArrayRef<mlir::Value>);
209209
mlir::Value genConjg(mlir::Type, llvm::ArrayRef<mlir::Value>);
210210
mlir::Value genDim(mlir::Type, llvm::ArrayRef<mlir::Value>);
211+
mlir::Value genDprod(mlir::Type, llvm::ArrayRef<mlir::Value>);
211212
template <Extremum, ExtremumBehavior>
212213
mlir::Value genExtremum(mlir::Type, llvm::ArrayRef<mlir::Value>);
213214
mlir::Value genFloor(mlir::Type, llvm::ArrayRef<mlir::Value>);
@@ -301,6 +302,7 @@ static constexpr IntrinsicHandler handlers[]{
301302
{"conjg", &I::genConjg},
302303
{"dim", &I::genDim},
303304
{"dble", &I::genConversion},
305+
{"dprod", &I::genDprod},
304306
{"floor", &I::genFloor},
305307
{"iand", &I::genIAnd},
306308
{"ichar", &I::genIchar},
@@ -1115,6 +1117,17 @@ mlir::Value IntrinsicLibrary::genDim(mlir::Type resultType,
11151117
return builder.create<mlir::SelectOp>(loc, cmp, diff, zero);
11161118
}
11171119

1120+
// DPROD
1121+
mlir::Value IntrinsicLibrary::genDprod(mlir::Type resultType,
1122+
llvm::ArrayRef<mlir::Value> args) {
1123+
assert(args.size() == 2);
1124+
assert(fir::isa_real(resultType) &&
1125+
"Result must be double precision in DPROD");
1126+
auto a = builder.createConvert(loc, resultType, args[0]);
1127+
auto b = builder.createConvert(loc, resultType, args[1]);
1128+
return builder.create<fir::MulfOp>(loc, a, b);
1129+
}
1130+
11181131
// FLOOR
11191132
mlir::Value IntrinsicLibrary::genFloor(mlir::Type resultType,
11201133
llvm::ArrayRef<mlir::Value> args) {

flang/test/Lower/intrinsics.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ subroutine dim_testi(i, j, k)
8686
k = dim(i, j)
8787
end subroutine
8888

89+
! DPROD
90+
! CHECK-LABEL: dprod_test
91+
subroutine dprod_test (x, y, z)
92+
real :: x,y
93+
double precision :: z
94+
z = dprod(x,y)
95+
! CHECK-DAG: %[[x:.*]] = fir.load %arg0
96+
! CHECK-DAG: %[[y:.*]] = fir.load %arg1
97+
! CHECK-DAG: %[[a:.*]] = fir.convert %[[x]] : (f32) -> f64
98+
! CHECK-DAG: %[[b:.*]] = fir.convert %[[y]] : (f32) -> f64
99+
! CHECK: %[[res:.*]] = fir.mulf %[[a]], %[[b]]
100+
! CHECK: fir.store %[[res]] to %arg2
101+
end subroutine
102+
89103
! CEILING
90104
! CHECK-LABEL: ceiling_test1
91105
subroutine ceiling_test1(i, a)

0 commit comments

Comments
 (0)