[all-commits] [llvm/llvm-project] deedc7: [Flang][OpenMP] Don't generate code for unreachabl...

Abid Qadeer via All-commits all-commits at lists.llvm.org
Mon Feb 16 01:32:04 PST 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: deedc7bfe3159dfe08d0a74c9822c6d5157c6fe8
      https://github.com/llvm/llvm-project/commit/deedc7bfe3159dfe08d0a74c9822c6d5157c6fe8
  Author: Abid Qadeer <haqadeer at amd.com>
  Date:   2026-02-16 (Mon, 16 Feb 2026)

  Changed paths:
    M flang/include/flang/Optimizer/OpenMP/Passes.td
    M flang/lib/Optimizer/OpenMP/CMakeLists.txt
    A flang/lib/Optimizer/OpenMP/DeleteUnreachableTargets.cpp
    M flang/lib/Optimizer/OpenMP/FunctionFiltering.cpp
    M flang/lib/Optimizer/Passes/Pipelines.cpp
    A flang/test/Lower/OpenMP/target-dead-code.f90
    A flang/test/Transforms/OpenMP/delete-unreachable-targets.mlir
    M mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

  Log Message:
  -----------
  [Flang][OpenMP] Don't generate code for unreachable target regions. (#178937)

When a target region is placed inside a constant false condition (e.g.,
`if (.false.)`), the dead code gets eliminated on the host side,
removing the `omp.target` operation entirely. However, the device-side
compilation pipeline is unaware of this elimination and attempts to
generate kernel code. Since the host never created offload metadata for
the eliminated target, the device-side kernel function lacks the
"kernel" attribute, causing `OpenMPOpt` to fail with an assertion when
it expects all outlined kernels to have this attribute. The problem can
be seen with the following code:

```fortran
program cele
  implicit none
  real :: V
  integer :: i
  if (.false.) then
    !$omp target teams distribute parallel do
    do i = 1, 5
      V = V * 2
    end do
    !$omp end target teams distribute parallel do
  end if
end program
```

It currently fails with the following assertion:

```
Assertion `omp::isOpenMPKernel(*Kernel) && "Expected kernel function!"' failed.
llvm/lib/Transforms/IPO/OpenMPOpt.cpp:4291
```

This PR adds `DeleteUnreachableTargetsPass` that identifies `omp.target`
operations in unreachable code blocks and removes them.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list