This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP] Fix conversion to LLVM IR for Fortran code with OpenMP SIMD directive and nested loop
ClosedPublic

Authored by domada on Aug 8 2022, 8:19 AM.

Details

Summary

Flang cannot convert to LLVM IR the following Fortran code:

subroutine simdloop_with_nested_loop
integer :: i, j
integer :: a(10)
 !$OMP SIMD
  do i=1, 10
   do j=1, 10
     a(i) = i
    end do
  end do
  !$OMP END SIMD
end subroutine

Command:
bin/bbc simdloop_with_nested_loop.f90 -fopenmp -emit-fir -o - | bin/tco
Fails with the error message:
loc("<stdin>":16:10): error: failed to legalize operation 'cf.br'

This patch enables compilation of the test case with SIMD directive and nested loop.

Diff Detail

Event Timeline

domada created this revision.Aug 8 2022, 8:19 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
domada requested review of this revision.Aug 8 2022, 8:19 AM
peixin requested changes to this revision.Aug 9 2022, 2:17 AM
peixin added inline comments.
flang/test/Lower/OpenMP/simd.f90
4 ↗(On Diff #450809)

This is not expected. You should add the test in flang/test/Fir/convert-to-llvm-openmp-and-fir.fir.

mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
126

SectionsOp is already there. Why do you add it repeatedly?

This revision now requires changes to proceed.Aug 9 2022, 2:17 AM
peixin edited reviewers, added: arnamoy10; removed: Restricted Project.Aug 9 2022, 2:19 AM
peixin removed a project: Restricted Project.
Herald added a project: Restricted Project. · View Herald TranscriptAug 9 2022, 2:19 AM
domada updated this revision to Diff 451100.Aug 9 2022, 4:19 AM

Scope of changes:

  1. moved test from flang/test/Lower/OpenMP/simd.f90 to flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
  2. removed duplicated addition of SectionsOp in populateOpenMPToLLVMConversionPatterns function
domada marked 2 inline comments as done.Aug 9 2022, 4:20 AM
domada added inline comments.
mlir/lib/Conversion/OpenMPToLLVM/OpenMPToLLVM.cpp
126

Copy-paste error.

domada marked an inline comment as done.Aug 9 2022, 4:42 AM
peixin accepted this revision.Aug 9 2022, 6:05 PM

LGTM. Please enable the CI passed before landing this patch. It seems the build bot stuck.

This revision is now accepted and ready to land.Aug 9 2022, 6:05 PM

Changes to MLIR code should ideally be tested with MLIR tree dialect tests. The test for this code should have been in https://github.com/llvm/llvm-project/blob/main/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir.