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

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Fri Feb 13 05:13:37 PST 2026


  Branch: refs/heads/users/ergawy/hoist_reduce_func_allocas
  Home:   https://github.com/llvm/llvm-project
  Commit: 2c74596271291eba384b572be24fa3cd11deaca1
      https://github.com/llvm/llvm-project/commit/2c74596271291eba384b572be24fa3cd11deaca1
  Author: ergawy <kareem.ergawy at amd.com>
  Date:   2026-02-13 (Fri, 13 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.



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