Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect no alias by TBAA due to a problem with metadata tags #1458

Open
1997alireza opened this issue Oct 30, 2024 · 0 comments · May be fixed by #1460
Open

Incorrect no alias by TBAA due to a problem with metadata tags #1458

1997alireza opened this issue Oct 30, 2024 · 0 comments · May be fixed by #1460

Comments

@1997alireza
Copy link

In Flang, variables are assigned distinct Type-Based Alias Analysis (TBAA) tags, even when they share identical types. This method, however, is insufficient for determining whether two variables from different functions are aliased. To address this, a separate metadata structure—referred to as the "type system"—is created for each function. Within this system, variables defined in a function are derived from its specific type system. For two variables to be confirmed as non-aliasing, they must originate from the same type system but possess distinct TBAA tags.

The type system metadata utilizes a simple counter assigned to functions based on their order of appearance. However, because this metadata is generated at the frontend, functions in separate modules can be assigned identical type systems. For example, the first and second functions in File A have type systems "Flang FAA 1" and "Flang FAA 2," respectively, while the first function in File B also be assigned "Flang FAA 1." This overlap can cause incorrect non-aliasing determinations between variables in the first functions of Files A and B.

In the following example, two accesses to the same element of an array are mistakenly identified as non-aliasing, which can lead to issues when the modify1 function is inlined.

      program main
      implicit none
      integer, parameter :: n = 5
      real :: arr1(n)
      integer :: i
      i = 0
      arr1 = 3.2
      arr1(i) = 4
      call modify1(arr1)
      call modify2(arr1)

      ! t1.4 from type system Flang FAA 1
      arr1(i) = arr1(i) + 2.5

      call printout(arr1)
      end program main
      subroutine modify1(arr1)
      implicit none
      real, intent(inout) :: arr1(:)

      ! t1.9 from type system Flang FAA 1
      arr1(0) = arr1(0) + 0.5
      end subroutine modify1

      subroutine modify2(arr1)
      implicit none
      real, intent(inout) :: arr1(:)
      arr1(2) = arr1(2) + 1.5
      end subroutine modify2

      subroutine printout(arr1)
      implicit none
      real, intent(in) :: arr1(:)
      integer :: i
      do i = 1, size(arr1)
        print arr1(i), " "
      enddo
      end subroutine printout

A simple solution is to append the hash of the module name to the type system metadata.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant