[flang-commits] [flang] [flang] Restructured TBAA trees in AddAliasTags pass. (PR #136725)

via flang-commits flang-commits at lists.llvm.org
Wed Apr 23 04:52:25 PDT 2025


================
@@ -0,0 +1,331 @@
+// RUN: fir-opt --fir-add-alias-tags %s | FileCheck --check-prefixes=ALL,DEFAULT %s
+// RUN: fir-opt --fir-add-alias-tags --local-alloc-tbaa %s | FileCheck --check-prefixes=ALL,LOCAL %s
+
+// Test AddAliasTagsPass creating sub-tree for TARGET/POINTER variables.
+
+// module data
+//   real :: glob(10)
+//   real, target :: globt(10)
+//   real, allocatable :: globa(:)
+//   real, allocatable, target :: globat(:)
+//   real, pointer :: globp(:)
+// end module data
+// subroutine test1(dummyf, dummyft, dummyas, dummyast, dummya, dummyat, dummyp)
+//   use data
+//   real :: dummyf(10)
+//   real, target :: dummyft(10)
+//   real :: dummyas(:)
+//   real, target :: dummyast(:)
+//   real, allocatable :: dummya(:)
+//   real, allocatable, target :: dummyat(:)
+//   real, pointer :: dummyp(:)
+//   real :: local(10)
+//   real, target :: localt(10)
+//   real, allocatable :: locala(:)
+//   real, allocatable, target :: localat(:)
+//   real, pointer :: localp(:)
+//   glob(1) = 1.0
+//   globt(1) = 1.0
+//   globa(1) = 1.0
+//   globat(1) = 1.0
+//   globp(1) = 1.0
+//   dummyf(1) = 1.0
+//   dummyft(1) = 1.0
+//   dummyas(1) = 1.0
+//   dummyast(1) = 1.0
+//   dummya(1) = 1.0
+//   dummyat(1) = 1.0
+//   dummyp(1) = 1.0
+//   local(1) = 1.0
+//   localt(1) = 1.0
+//   locala(1) = 1.0
+//   localat(1) = 1.0
+//   localp(1) = 1.0
+// end subroutine test1
+
+// "Flang function root _QPtest1"
+// |
+// "any access"
+// |
+// |- "descriptor member"
+// |- "any data access"
+//    |
+//    |- "dummy arg data"
+//    |  |
+//    |  |- "dummy arg data/_QFtest1Edummyf"
+//    |  |- "dummy arg data/_QFtest1Edummyas"
+//    |  |- "dummy arg data/_QFtest1Edummya"
+//    |
+//    |- "target data" <- all pointers and taget dummys
+//       |
+//       |- "global data"
+//       |  |
+//       |  |- "global data/_QMdataEglob"
+//       |  |- "global data/_QMdataEglobt"
+//       |
+//       |- "direct data" - "direct data/_QMdataEgloba"
+//       |  |
+//       |  |- "direct data/_QMdataEgloba"
+//       |  |- "direct data/_QMdataEglobat"
+//       |
+//       |- "allocated data"
+//          |
+//          |- "allocated data/_QFtest1Elocal"
+//          |- "allocated data/_QFtest1Elocalt"
+//          |- "allocated data/_QFtest1Elocala"
+//          |- "allocated data/_QFtest1Elocalat"
----------------
jeanPerier wrote:

I wonder if creating tags for each variables in "allocated data" and "global data" really makes a difference. I would imagine LLVM is already clever enough to know/deduce that two global addresses cannot alias if they do not come from the same global (and the same with alloca). I am not against it, but I imagine this is growing the metadata size a bit.

Also, for common block, will it create different tags for each common block members, or just one with the common block global name? Since they technically share the same storage, it would be safer to have a single tag for them I think. Same with local/global equivalences, but here I think we should probably fall into the POINTER cases currently (worth adding a test though).

I totally understand why adding tags for each variables makes a difference in the "direct data" and "dummy arg data" cases.

https://github.com/llvm/llvm-project/pull/136725


More information about the flang-commits mailing list