[flang-commits] [flang] 41f478f - [Flang][HLFIR] Relax size check for dot_product intrinsic

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Tue Jul 18 02:27:22 PDT 2023


Author: Kiran Chandramohan
Date: 2023-07-18T09:26:58Z
New Revision: 41f478f0419781f6968de0661ce570916c9de863

URL: https://github.com/llvm/llvm-project/commit/41f478f0419781f6968de0661ce570916c9de863
DIFF: https://github.com/llvm/llvm-project/commit/41f478f0419781f6968de0661ce570916c9de863.diff

LOG: [Flang][HLFIR] Relax size check for dot_product intrinsic

If the size of one of the operand arrays is not known at compile
time, do not issue a size mismatch error sinc they could match at
runtime.

Fixes the compilation error in polyhedron/induct2.

Reviewed By: tblah, vzakhari

Differential Revision: https://reviews.llvm.org/D155302

Added: 
    

Modified: 
    flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
    flang/test/Lower/HLFIR/dot_product.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
index 51b44d7bb2f847..37a1d9acd3d9d4 100644
--- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
+++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp
@@ -733,7 +733,9 @@ mlir::LogicalResult hlfir::DotProductOp::verify() {
   int64_t lhsSize = lhsShape[0];
   int64_t rhsSize = rhsShape[0];
 
-  if (lhsSize != rhsSize)
+  constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent();
+  if ((lhsSize != unknownExtent) && (rhsSize != unknownExtent) &&
+      (lhsSize != rhsSize))
     return emitOpError("both arrays must have the same size");
 
   if (mlir::isa<fir::LogicalType>(lhsEleTy) !=

diff  --git a/flang/test/Lower/HLFIR/dot_product.f90 b/flang/test/Lower/HLFIR/dot_product.f90
index 47e623ae253921..890dc4abca496b 100644
--- a/flang/test/Lower/HLFIR/dot_product.f90
+++ b/flang/test/Lower/HLFIR/dot_product.f90
@@ -70,3 +70,15 @@ subroutine dot_product4(lhs, rhs, res)
 ! CHECK-NEXT:    hlfir.assign %[[PROD]] to %[[RES_VAR]]#0 : i32, !fir.ref<i32>
 ! CHECK-NEXT:    return
 ! CHECK-NEXT:   }
+
+! CHECK-LABEL: func.func @_QPdot_product5
+! CHECK:    %[[LHS:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFdot_product5Elhs"} : (!fir.box<!fir.array<?xi32>>) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
+! CHECK:    %[[C3:.*]] = arith.constant 3 : index
+! CHECK:    %[[RHS_SHAPE:.*]] = fir.shape %[[C3]] : (index) -> !fir.shape<1>
+! CHECK:    %[[RHS:.*]]:2 = hlfir.declare %{{.*}}(%[[RHS_SHAPE]]) {uniq_name = "_QFdot_product5Erhs"} : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> (!fir.ref<!fir.array<3xi32>>, !fir.ref<!fir.array<3xi32>>)
+! CHECK:    {{.*}} = hlfir.dot_product %[[LHS]]#0 %[[RHS]]#0 {fastmath = #arith.fastmath<contract>} : (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<3xi32>>) -> i32
+subroutine dot_product5(lhs, rhs, res)
+  integer :: lhs(:), rhs(3)
+  integer :: res
+  res = dot_product(lhs, rhs)
+endsubroutine


        


More information about the flang-commits mailing list