[flang-commits] [flang] [Flang][OpenMP] Fix lastprivate store issue (PR #92777)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Mon May 20 08:56:48 PDT 2024


https://github.com/kiranchandramohan created https://github.com/llvm/llvm-project/pull/92777

Fix an issue where the lastprivate variable type is different from the type used for the index of the loop.

Fixes #79780

>From 4e3861d10ff45435bde82518c4356a1b03b4887e Mon Sep 17 00:00:00 2001
From: Kiran Chandramohan <kiran.chandramohan at arm.com>
Date: Mon, 20 May 2024 15:51:29 +0000
Subject: [PATCH] [Flang][OpenMP] Fix lastprivate store issue

Fix an issue where the lastprivate variable type is different
from the type used for the index of the loop.

Fixes #79780
---
 .../lib/Lower/OpenMP/DataSharingProcessor.cpp |  4 +++-
 flang/test/Lower/OpenMP/lastprivate-iv.f90    | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
index 82d8d8dd98ea2..3f1a939e33d91 100644
--- a/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
+++ b/flang/lib/Lower/OpenMP/DataSharingProcessor.cpp
@@ -226,7 +226,9 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
       auto ifOp = firOpBuilder.create<fir::IfOp>(loc, cmpOp, /*else*/ false);
       firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front());
       assert(loopIV && "loopIV was not set");
-      firOpBuilder.create<fir::StoreOp>(loopOp.getLoc(), v, loopIV);
+      mlir::Value cvtV = firOpBuilder.createConvert(
+          loc, fir::unwrapPassByRefType(loopIV.getType()), v);
+      firOpBuilder.create<fir::StoreOp>(loc, cvtV, loopIV);
       lastPrivIP = firOpBuilder.saveInsertionPoint();
     } else if (mlir::isa<mlir::omp::SectionsOp>(op)) {
       // Already handled by genOMP()
diff --git a/flang/test/Lower/OpenMP/lastprivate-iv.f90 b/flang/test/Lower/OpenMP/lastprivate-iv.f90
index 24c20281b9c38..718c9c99370e9 100644
--- a/flang/test/Lower/OpenMP/lastprivate-iv.f90
+++ b/flang/test/Lower/OpenMP/lastprivate-iv.f90
@@ -70,3 +70,22 @@ subroutine lastprivate_iv_dec()
   end do
   !$omp end do
 end subroutine
+
+
+!CHECK-LABEL:  @_QPlastprivate_iv_i1
+subroutine lastprivate_iv_i1
+  integer*1 :: i1
+  i1=0
+!CHECK:    omp.wsloop
+!CHECK:      omp.loop_nest
+!CHECK:        fir.if %{{.*}} {
+!CHECK:          %[[I8_VAL:.*]] = fir.convert %{{.*}} : (i32) -> i8
+!CHECK:          fir.store %[[I8_VAL]] to %[[IV:.*]]#1 : !fir.ref<i8>
+!CHECK:          %[[IV_VAL:.*]] = fir.load %[[IV]]#0 : !fir.ref<i8>
+!CHECK:          hlfir.assign %[[IV_VAL]] to %{{.*}}#0 temporary_lhs : i8, !fir.ref<i8>
+!CHECK:        }
+  !$omp do lastprivate(i1)
+  do i1=1,8
+  enddo
+!$omp end do
+end subroutine



More information about the flang-commits mailing list