-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Flang][OpenMP] Fix lastprivate store issue #92777
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flang][OpenMP] Fix lastprivate store issue #92777
Conversation
Fix an issue where the lastprivate variable type is different from the type used for the index of the loop. Fixes llvm#79780
@llvm/pr-subscribers-flang-openmp Author: Kiran Chandramohan (kiranchandramohan) ChangesFix an issue where the lastprivate variable type is different from the type used for the index of the loop. Fixes #79780 Full diff: https://github.com/llvm/llvm-project/pull/92777.diff 2 Files Affected:
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
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Kiran Chandramohan (kiranchandramohan) ChangesFix an issue where the lastprivate variable type is different from the type used for the index of the loop. Fixes #79780 Full diff: https://github.com/llvm/llvm-project/pull/92777.diff 2 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the bugfix
@@ -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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it would be cleaner to use fir::FirOpBUilder::createStoreWithConvert
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. The change looks good.
Fix an issue where the lastprivate variable type is different from the type used for the index of the loop.
Fixes #79780