@@ -1181,6 +1181,18 @@ static Value getReductionInitValue(mlir::Location loc, mlir::Type type,
1181
1181
unsigned bits = type.getIntOrFloatBitWidth ();
1182
1182
int64_t maxInt = llvm::APInt::getSignedMaxValue (bits).getSExtValue ();
1183
1183
return builder.createIntegerConstant (loc, type, maxInt);
1184
+ } else if (reductionOpName.contains (" ior" )) {
1185
+ unsigned bits = type.getIntOrFloatBitWidth ();
1186
+ int64_t zeroInt = llvm::APInt::getZero (bits).getSExtValue ();
1187
+ return builder.createIntegerConstant (loc, type, zeroInt);
1188
+ } else if (reductionOpName.contains (" ieor" )) {
1189
+ unsigned bits = type.getIntOrFloatBitWidth ();
1190
+ int64_t zeroInt = llvm::APInt::getZero (bits).getSExtValue ();
1191
+ return builder.createIntegerConstant (loc, type, zeroInt);
1192
+ } else if (reductionOpName.contains (" iand" )) {
1193
+ unsigned bits = type.getIntOrFloatBitWidth ();
1194
+ int64_t allOnInt = llvm::APInt::getAllOnes (bits).getSExtValue ();
1195
+ return builder.createIntegerConstant (loc, type, allOnInt);
1184
1196
} else {
1185
1197
if (type.isa <FloatType>())
1186
1198
return builder.create <mlir::arith::ConstantOp>(
@@ -1268,6 +1280,15 @@ createReductionDecl(fir::FirOpBuilder &builder, llvm::StringRef reductionOpName,
1268
1280
reductionOp =
1269
1281
getReductionOperation<mlir::arith::MinFOp, mlir::arith::MinSIOp>(
1270
1282
builder, type, loc, op1, op2);
1283
+ } else if (name->source == " ior" ) {
1284
+ assert ((type.isIntOrIndex ()) && " only integer is expected" );
1285
+ reductionOp = builder.create <mlir::arith::OrIOp>(loc, op1, op2);
1286
+ } else if (name->source == " ieor" ) {
1287
+ assert ((type.isIntOrIndex ()) && " only integer is expected" );
1288
+ reductionOp = builder.create <mlir::arith::XOrIOp>(loc, op1, op2);
1289
+ } else if (name->source == " iand" ) {
1290
+ assert ((type.isIntOrIndex ()) && " only integer is expected" );
1291
+ reductionOp = builder.create <mlir::arith::AndIOp>(loc, op1, op2);
1271
1292
} else {
1272
1293
TODO (loc, " Reduction of some intrinsic operators is not supported" );
1273
1294
}
@@ -1594,7 +1615,9 @@ static void genOMP(Fortran::lower::AbstractConverter &converter,
1594
1615
&redOperator.u )) {
1595
1616
if (const auto *name{Fortran::parser::Unwrap<Fortran::parser::Name>(
1596
1617
reductionIntrinsic)}) {
1597
- if ((name->source != " max" ) && (name->source != " min" )) {
1618
+ if ((name->source != " max" ) && (name->source != " min" ) &&
1619
+ (name->source != " ior" ) && (name->source != " ieor" ) &&
1620
+ (name->source != " iand" )) {
1598
1621
TODO (currentLocation,
1599
1622
" Reduction of intrinsic procedures is not supported" );
1600
1623
}
@@ -2364,7 +2387,10 @@ void Fortran::lower::genOpenMPReduction(
2364
2387
&redOperator.u )) {
2365
2388
if (const auto *name{Fortran::parser::Unwrap<Fortran::parser::Name>(
2366
2389
reductionIntrinsic)}) {
2367
- if ((name->source != " max" ) && (name->source != " min" )) {
2390
+ std::string redName = name->ToString ();
2391
+ if ((name->source != " max" ) && (name->source != " min" ) &&
2392
+ (name->source != " ior" ) && (name->source != " ieor" ) &&
2393
+ (name->source != " iand" )) {
2368
2394
continue ;
2369
2395
}
2370
2396
for (const auto &ompObject : objectList.v ) {
@@ -2383,12 +2409,21 @@ void Fortran::lower::genOpenMPReduction(
2383
2409
findReductionChain (loadVal, &reductionVal);
2384
2410
if (reductionOp == nullptr )
2385
2411
continue ;
2386
- assert (mlir::isa<mlir::arith::SelectOp>(reductionOp) &&
2387
- " Selection Op not found in reduction intrinsic" );
2388
- mlir::Operation *compareOp =
2389
- getCompareFromReductionOp (reductionOp, loadVal);
2390
- updateReduction (compareOp, firOpBuilder, loadVal,
2391
- reductionVal);
2412
+
2413
+ if (redName == " max" || redName == " min" ) {
2414
+ assert (mlir::isa<mlir::arith::SelectOp>(reductionOp) &&
2415
+ " Selection Op not found in reduction intrinsic" );
2416
+ mlir::Operation *compareOp =
2417
+ getCompareFromReductionOp (reductionOp, loadVal);
2418
+ updateReduction (compareOp, firOpBuilder, loadVal,
2419
+ reductionVal);
2420
+ }
2421
+ if (redName == " ior" || redName == " ieor" ||
2422
+ redName == " iand" ) {
2423
+
2424
+ updateReduction (reductionOp, firOpBuilder, loadVal,
2425
+ reductionVal);
2426
+ }
2392
2427
}
2393
2428
}
2394
2429
}
0 commit comments