Skip to content

[flang] missed optimization of product intrinsic #169433

@foxtran

Description

@foxtran

For the following code:

subroutine sum_and_prod(v, n, s, p)
  implicit none (type, external)
  integer, intent(in) :: n
  real, intent(in) :: v(n)
  real, intent(out) :: s, p
  s = sum(v)
  p = product(v)
end subroutine sum_and_prod

flang produces native ASM code for summation, while for product there is a call to runtime library.

Even if length of vector is known (and small):

subroutine sum_and_prod_vec3(v, s, p)
  implicit none (type, external)
  real, intent(in) :: v(3)
  real, intent(out) :: s, p
  s = sum(v)
  p = product(v)
end subroutine sum_and_prod_vec3

ASM still have call of runtime library.

It would be nice to avoid any calls especially for short arrays.

ASM output:
https://godbolt.org/z/d3Edr9GG4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions