Skip to content

Commit 41f478f

Browse files
[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
1 parent 505335a commit 41f478f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,9 @@ mlir::LogicalResult hlfir::DotProductOp::verify() {
733733
int64_t lhsSize = lhsShape[0];
734734
int64_t rhsSize = rhsShape[0];
735735

736-
if (lhsSize != rhsSize)
736+
constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent();
737+
if ((lhsSize != unknownExtent) && (rhsSize != unknownExtent) &&
738+
(lhsSize != rhsSize))
737739
return emitOpError("both arrays must have the same size");
738740

739741
if (mlir::isa<fir::LogicalType>(lhsEleTy) !=

flang/test/Lower/HLFIR/dot_product.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,15 @@ subroutine dot_product4(lhs, rhs, res)
7070
! CHECK-NEXT: hlfir.assign %[[PROD]] to %[[RES_VAR]]#0 : i32, !fir.ref<i32>
7171
! CHECK-NEXT: return
7272
! CHECK-NEXT: }
73+
74+
! CHECK-LABEL: func.func @_QPdot_product5
75+
! CHECK: %[[LHS:.*]]:2 = hlfir.declare %{{.*}} {uniq_name = "_QFdot_product5Elhs"} : (!fir.box<!fir.array<?xi32>>) -> (!fir.box<!fir.array<?xi32>>, !fir.box<!fir.array<?xi32>>)
76+
! CHECK: %[[C3:.*]] = arith.constant 3 : index
77+
! CHECK: %[[RHS_SHAPE:.*]] = fir.shape %[[C3]] : (index) -> !fir.shape<1>
78+
! 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>>)
79+
! CHECK: {{.*}} = hlfir.dot_product %[[LHS]]#0 %[[RHS]]#0 {fastmath = #arith.fastmath<contract>} : (!fir.box<!fir.array<?xi32>>, !fir.ref<!fir.array<3xi32>>) -> i32
80+
subroutine dot_product5(lhs, rhs, res)
81+
integer :: lhs(:), rhs(3)
82+
integer :: res
83+
res = dot_product(lhs, rhs)
84+
endsubroutine

0 commit comments

Comments
 (0)