Skip to content

Commit 2428b6e

Browse files
authored
[Flang][MLIR][OpenMP] Fix Target Data if (present(...)) causing LLVM-IR branching error (#123771)
Currently if we generate code for the below target data map that uses an optional mapping: !$omp target data if(present(a)) map(alloc:a) do i = 1, 10 a(i) = i end do !$omp end target data We yield an LLVM-IR error as the branch for the else path is not generated. This occurs because we enter the NoDupPriv path of the call back function when generating the else branch, however, the emitBranch function needs to be set to a block for it to functionally generate and link in a follow up branch. The NoDupPriv path currently doesn't do this, while it's not supposed to generate anything (as far as I am aware) we still need to at least set the builders placement back so that it emits the appropriate follow up branch. This avoids the missing terminator LLVM-IR verification error by correctly generating the follow up branch.
1 parent 4186805 commit 2428b6e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -3658,6 +3658,9 @@ convertOmpTargetData(Operation *op, llvm::IRBuilderBase &builder,
36583658
}
36593659
break;
36603660
case BodyGenTy::DupNoPriv:
3661+
// We must always restoreIP regardless of doing anything the caller
3662+
// does not restore it, leading to incorrect (no) branch generation.
3663+
builder.restoreIP(codeGenIP);
36613664
break;
36623665
case BodyGenTy::NoPriv:
36633666
// If device info is available then region has already been generated
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
! Offloading test that tests that if(present(a)) compiles and executes without
2+
! causing any compilation errors, primarily a regression test that does not
3+
! yield interesting results.
4+
! REQUIRES: flang, amdgpu
5+
6+
! RUN: %libomptarget-compile-fortran-run-and-check-generic
7+
module mod
8+
implicit none
9+
contains
10+
subroutine routine(a)
11+
implicit none
12+
real, dimension(:), optional :: a
13+
integer :: i
14+
!$omp target data if(present(a)) map(alloc:a)
15+
do i = 1, 10
16+
a(i) = i
17+
end do
18+
!$omp end target data
19+
end subroutine routine
20+
end module mod
21+
22+
program main
23+
use mod
24+
real :: a(10)
25+
call routine(a)
26+
print *, a
27+
end program main
28+
29+
! CHECK: 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.

0 commit comments

Comments
 (0)