llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.9k stars 11.51k forks source link

[Flang] Lowering fails with -O3 inside where clause #104464

Open lukasm91 opened 3 weeks ago

lukasm91 commented 3 weeks ago

Consider this code (simplified from a large code):

module m1
  implicit none

  type a
    integer              :: b
    real, dimension(0:234) :: c
  end type

  type(a), allocatable, dimension(:)      :: h

end module

module m2
  use m1
  implicit none
contains
  subroutine m(d,e,f,g)

    implicit none

    real, intent(in)    :: d(:)
    real, intent(inout), dimension(:,:)   :: e
    real, intent(inout), dimension(:)     :: f
    real, intent(inout), dimension(:)     :: g

    where ( f(:) <= 1.)
      g(:) = h(1)%c(0) + matmul(e(:,:),h(1)%c(1:h(1)%b))
    endwhere

  end subroutine
end module

Compiling with -O0 works perfectly fine, with -O3 I get error: loc("/app/example.f90":27:7): null operand found error: Lowering to LLVM IR failed error: loc("/app/example.f90":1:1): LLVM Translation failed for operation: fir.global error: failed to create the LLVM module

See https://fortran.godbolt.org/z/8Wfxn1dsa

Workaround is to split the assignment into two lines, i.e.

g(:) = h(1)%c(0) g(:) = g(:) + matmul(e(:,:),h(1)%c(1:h(1)%b))

llvmbot commented 3 weeks ago

@llvm/issue-subscribers-flang-ir

Author: None (lukasm91)

Consider this code (simplified from a large code): ``` module m1 implicit none type a integer :: b real, dimension(0:234) :: c end type type(a), allocatable, dimension(:) :: h end module module m2 use m1 implicit none contains subroutine m(d,e,f,g) implicit none real, intent(in) :: d(:) real, intent(inout), dimension(:,:) :: e real, intent(inout), dimension(:) :: f real, intent(inout), dimension(:) :: g where ( f(:) <= 1.) g(:) = h(1)%c(0) + matmul(e(:,:),h(1)%c(1:h(1)%b)) endwhere end subroutine end module ``` Compiling with -O0 works perfectly fine, with -O3 I get error: loc("/app/example.f90":27:7): null operand found error: Lowering to LLVM IR failed error: loc("/app/example.f90":1:1): LLVM Translation failed for operation: fir.global error: failed to create the LLVM module See https://fortran.godbolt.org/z/8Wfxn1dsa Workaround is to split the assignment into two lines, i.e. g(:) = h(1)%c(0) g(:) = g(:) + matmul(e(:,:),h(1)%c(1:h(1)%b))
llvmbot commented 3 weeks ago

@llvm/issue-subscribers-bug

Author: None (lukasm91)

Consider this code (simplified from a large code): ``` module m1 implicit none type a integer :: b real, dimension(0:234) :: c end type type(a), allocatable, dimension(:) :: h end module module m2 use m1 implicit none contains subroutine m(d,e,f,g) implicit none real, intent(in) :: d(:) real, intent(inout), dimension(:,:) :: e real, intent(inout), dimension(:) :: f real, intent(inout), dimension(:) :: g where ( f(:) <= 1.) g(:) = h(1)%c(0) + matmul(e(:,:),h(1)%c(1:h(1)%b)) endwhere end subroutine end module ``` Compiling with -O0 works perfectly fine, with -O3 I get error: loc("/app/example.f90":27:7): null operand found error: Lowering to LLVM IR failed error: loc("/app/example.f90":1:1): LLVM Translation failed for operation: fir.global error: failed to create the LLVM module See https://fortran.godbolt.org/z/8Wfxn1dsa Workaround is to split the assignment into two lines, i.e. g(:) = h(1)%c(0) g(:) = g(:) + matmul(e(:,:),h(1)%c(1:h(1)%b))