[all-commits] [llvm/llvm-project] da466e: [OMPIRBuilder] Hoist alloca's to entry blocks of c...

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Mon Feb 16 21:58:08 PST 2026


  Branch: refs/heads/users/ergawy/hoist_reduce_func_allocas
  Home:   https://github.com/llvm/llvm-project
  Commit: da466e5dc1fcae7bbe069b62002b62274a89a5c4
      https://github.com/llvm/llvm-project/commit/da466e5dc1fcae7bbe069b62002b62274a89a5c4
  Author: ergawy <kareem.ergawy at amd.com>
  Date:   2026-02-16 (Mon, 16 Feb 2026)

  Changed paths:
    M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
    M mlir/test/Target/LLVMIR/allocatable_gpu_reduction.mlir

  Log Message:
  -----------
  [OMPIRBuilder] Hoist alloca's to entry blocks of compiler-emitted GPU reduction functions

Fixes a bug in GPU reductions when `-O0` was used to compile GPU
reductions. There were invalid memory accesses at runtime for the
following example:

```fortran
program test_array_reduction()
  integer :: red_array(1)
  integer :: i

  red_array = 0

  !$omp target teams distribute parallel do reduction(+:red_array)
  do i = 1, 100
    red_array(1) = red_array(1) + 4422
  end do
  !$omp end target teams distribute parallel do

  print *, red_array
end program test_array_reduction
```

The issue was caused by alloca's for some temp values in the combiner
region of the reduction op being inlined beyond the entry blocks of the
GPU reduction functions emitted by the compiler.

This PR fixes the issue by hoisting all alloca's to the entry block
after the reduction functions are completely emitted by the compiler.


  Commit: 8c765ba3c16e8433f773e4b6fd3177dd0e11aa88
      https://github.com/llvm/llvm-project/commit/8c765ba3c16e8433f773e4b6fd3177dd0e11aa88
  Author: ergawy <kareem.ergawy at amd.com>
  Date:   2026-02-16 (Mon, 16 Feb 2026)

  Changed paths:
    M llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

  Log Message:
  -----------
  add comment and refactor hoisting utils


Compare: https://github.com/llvm/llvm-project/compare/2c7459627129...8c765ba3c16e

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