[flang-commits] [flang] da9f890 - [Flang][OpenMP] Fix crash in MAX intrinsic reduction

Kavitha Natarajan via flang-commits flang-commits at lists.llvm.org
Wed Mar 29 11:11:42 PDT 2023


Author: Kavitha Natarajan
Date: 2023-03-29T23:41:21+05:30
New Revision: da9f890d09e78614da86ce2a14e2e92786038497

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

LOG: [Flang][OpenMP] Fix crash in MAX intrinsic reduction

This patch fixes a crash that appear in an OpenMP MAX intrinsic
reduction when the reduction is not expressed using MAX intrinsic
function. Updated flang/test/Lower/OpenMP/wsloop-reduction-max.f90
test case with additional way of expressing MAX reduction.

Reviewed By: kiranchandramohan

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

Added: 
    

Modified: 
    flang/lib/Lower/OpenMP.cpp
    flang/test/Lower/OpenMP/wsloop-reduction-max.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index e3b4fb820d80b..5feff7f3caade 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2324,6 +2324,7 @@ void Fortran::lower::genOpenMPReduction(
                     // Match the pattern here.
                     mlir::Operation *reductionOp =
                         findReductionChain(loadVal, &reductionVal);
+                    if (reductionOp == nullptr) continue;
                     assert(mlir::isa<mlir::arith::SelectOp>(reductionOp) &&
                            "Selection Op not found in reduction intrinsic");
                     mlir::Operation *compareOp =

diff  --git a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90 b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
index 0db5b7f813d74..44ea05432defb 100644
--- a/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
+++ b/flang/test/Lower/OpenMP/wsloop-reduction-max.f90
@@ -63,4 +63,13 @@ subroutine reduction_max_real(y)
   !$omp end do
   !$omp end parallel
   print *, x
+
+  !$omp parallel
+  !$omp do reduction(max:x)
+  do i=1, 100
+    if (y(i) .gt. x) x = y(i)
+  end do
+  !$omp end do
+  !$omp end parallel
+  print *, x
 end subroutine


        


More information about the flang-commits mailing list