[Flang][OpenMP] Compilation error when capture-statement described in atomic capture construct contains a different type
Version of flang-new : 19.0.0(8930ba98e01bc66949e482b396f8389d64388359)AArch64
When capture-statement described in atomic capture construct contains a different type, the compilation terminates abnormally.
Although the results of this compilation and #93441 are different, they seem to contain similar issues.
Compilation ends normally in the following cases:
- Do not specify the compilation option (
-fopenmp)
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
OMP_3_O_007_4_atm_type_049_fo_222.f90:
subroutine sub2()
real(kind=4) :: s_x_r2
real(kind=16) :: s_v_r16
complex(kind=4) :: s_expr_c2
s_x_r2 =10.0
s_v_r16 = 10.0
s_expr_c2 =(10.0,0.0)
!$omp atomic capture
s_v_r16 = s_x_r2
s_x_r2 = s_x_r2 + s_expr_c2
!$omp end atomic
write(6,*) "s_v_r16 = ", s_v_r16, " s_x_r2 = " , s_x_r2
end subroutine sub2
program main
call sub2()
end program main
$ flang-new -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp40_EXA/OMP_3_O_007_4_atm_type_049_fo_222.f90":7:3): the type of the operand must be a pointer type whose element type is the same as that of the region argument
error: verification of lowering to FIR failed
$
$ gfortran -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000000 s_x_r2 = 20.0000000
$
$ ifort -qopenmp -diag-disable=10448 OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000 s_x_r2 = 20.00000
$
@llvm/issue-subscribers-openmp
Author: None (ohno-fj)
When capture-statement described in atomic capture construct contains a different type, the compilation terminates abnormally.
Although the results of this compilation and #93441 are different, they seem to contain similar issues.
Compilation ends normally in the following cases:
- Do not specify the compilation option (
-fopenmp)
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
OMP_3_O_007_4_atm_type_049_fo_222.f90:
subroutine sub2()
real(kind=4) :: s_x_r2
real(kind=16) :: s_v_r16
complex(kind=4) :: s_expr_c2
s_x_r2 =10.0
s_v_r16 = 10.0
s_expr_c2 =(10.0,0.0)
!$omp atomic capture
s_v_r16 = s_x_r2
s_x_r2 = s_x_r2 + s_expr_c2
!$omp end atomic
write(6,*) "s_v_r16 = ", s_v_r16, " s_x_r2 = " , s_x_r2
end subroutine sub2
program main
call sub2()
end program main
$ flang-new -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp40_EXA/OMP_3_O_007_4_atm_type_049_fo_222.f90":7:3): the type of the operand must be a pointer type whose element type is the same as that of the region argument
error: verification of lowering to FIR failed
$
$ gfortran -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000000 s_x_r2 = 20.0000000
$
$ ifort -qopenmp -diag-disable=10448 OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000 s_x_r2 = 20.00000
$
@llvm/issue-subscribers-flang-ir
Author: None (ohno-fj)
When capture-statement described in atomic capture construct contains a different type, the compilation terminates abnormally.
Although the results of this compilation and #93441 are different, they seem to contain similar issues.
Compilation ends normally in the following cases:
- Do not specify the compilation option (
-fopenmp)
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
OMP_3_O_007_4_atm_type_049_fo_222.f90:
subroutine sub2()
real(kind=4) :: s_x_r2
real(kind=16) :: s_v_r16
complex(kind=4) :: s_expr_c2
s_x_r2 =10.0
s_v_r16 = 10.0
s_expr_c2 =(10.0,0.0)
!$omp atomic capture
s_v_r16 = s_x_r2
s_x_r2 = s_x_r2 + s_expr_c2
!$omp end atomic
write(6,*) "s_v_r16 = ", s_v_r16, " s_x_r2 = " , s_x_r2
end subroutine sub2
program main
call sub2()
end program main
$ flang-new -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp40_EXA/OMP_3_O_007_4_atm_type_049_fo_222.f90":7:3): the type of the operand must be a pointer type whose element type is the same as that of the region argument
error: verification of lowering to FIR failed
$
$ gfortran -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000000 s_x_r2 = 20.0000000
$
$ ifort -qopenmp -diag-disable=10448 OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000 s_x_r2 = 20.00000
$
@llvm/issue-subscribers-flang-ir
Author: None (ohno-fj)
When capture-statement described in atomic capture construct contains a different type, the compilation terminates abnormally.
Although the results of this compilation and #93441 are different, they seem to contain similar issues.
Compilation ends normally in the following cases:
- Do not specify the compilation option (
-fopenmp)
The following are the test program, Flang-new, Gfortran and ifort compilation/execution result.
OMP_3_O_007_4_atm_type_049_fo_222.f90:
subroutine sub2()
real(kind=4) :: s_x_r2
real(kind=16) :: s_v_r16
complex(kind=4) :: s_expr_c2
s_x_r2 =10.0
s_v_r16 = 10.0
s_expr_c2 =(10.0,0.0)
!$omp atomic capture
s_v_r16 = s_x_r2
s_x_r2 = s_x_r2 + s_expr_c2
!$omp end atomic
write(6,*) "s_v_r16 = ", s_v_r16, " s_x_r2 = " , s_x_r2
end subroutine sub2
program main
call sub2()
end program main
$ flang-new -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
error: loc("/work/home/ohno/CT/test/fort/tp/reproducerJ/fomp_omp40_EXA/OMP_3_O_007_4_atm_type_049_fo_222.f90":7:3): the type of the operand must be a pointer type whose element type is the same as that of the region argument
error: verification of lowering to FIR failed
$
$ gfortran -fopenmp OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000000 s_x_r2 = 20.0000000
$
$ ifort -qopenmp -diag-disable=10448 OMP_3_O_007_4_atm_type_049_fo_222.f90
s_v_r16 = 10.0000000000000000000000000000000 s_x_r2 = 20.00000
$
FYI, I'm getting a new error now:
flang-20: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
error: loc("/home/carlos.seo/Developer/sandbox/llvm-94177/test.f90":7:3): 'fir.convert' op invalid type conversion'complex<f32>' / 'f32'
error: verification of lowering to FIR failed
FYI, this doesn't crash now.
flang-21: warning: OpenMP support in flang is still experimental [-Wexperimental-option]
error: Semantic errors in test.f90
./test.f90:3:3: error: REAL(KIND=16) is not an enabled type for this target
real(kind=16) :: s_v_r16
^^^^^^^^^^^^^^^^^^^^^^^^^^^
I tried on a system which does support REAL(16) and the old error is still present. I think you could reproduce by changing real(16) to real(8)
This issue is now resolved with https://github.com/llvm/llvm-project/pull/138163
However, because of mixing complex and primitive types in atomic construct, there is a %25 = "fir.convert"(%24) : (complex<f32>) -> f32 emitted which complains fir.convert op invalid type conversion complex
FIR with the linked patch. Notice how the atomic read has compatible types; %0 is an alloca not mentioned here, which will be converted and stored to s_v_r16 after the capture region.
"omp.atomic.capture"() ({
"omp.atomic.read"(%7#0, %0) <{element_type = f32}> : (!fir.ref<f32>, !fir.ref<f32>) -> ()
"omp.atomic.update"(%7#0) ({
^bb0(%arg0: f32):
%20 = "arith.constant"() <{value = 0.000000e+00 : f32}> : () -> f32
%21 = "fir.undefined"() : () -> complex<f32>
%22 = "fir.insert_value"(%21, %arg0) <{coor = [0 : index]}> : (complex<f32>, f32) -> complex<f32>
%23 = "fir.insert_value"(%22, %20) <{coor = [1 : index]}> : (complex<f32>, f32) -> complex<f32>
%24 = "fir.addc"(%23, %17) <{fastmath = #arith.fastmath<contract>}> : (complex<f32>, complex<f32>) -> complex<f32>
%25 = "fir.convert"(%24) : (complex<f32>) -> f32
"omp.yield"(%25) : (f32) -> ()
}) : (!fir.ref<f32>) -> ()
}) : () -> ()
cc @kiranktp @tblah
A sample test case:
subroutine sub2()
real(kind=4) :: s_x_r2
real(kind=16) :: s_v_r16
double precision :: s_expr_c2
s_x_r2 =10.0
s_v_r16 = 10.0
!$omp atomic capture
s_v_r16 = s_x_r2
s_x_r2 = s_x_r2 + s_expr_c2
!$omp end atomic
write(6,*) "s_v_r16 = ", s_v_r16, " s_x_r2 = " , s_x_r2
end subroutine sub2
program main
call sub2()
end program main
compiles correctly and produces the output:
s_v_r16 = 10. s_x_r2 = 10.
I have created a new issue for the atomic update issue: https://github.com/llvm/llvm-project/issues/138396, and have offered a fix in a PR https://github.com/llvm/llvm-project/pull/138397
Fixed by https://github.com/llvm/llvm-project/pull/138163