[all-commits] [llvm/llvm-project] 90da61: [flang] Use outermost fir.dummy_scope for TBAA of ...

Slava Zakharin via All-commits all-commits at lists.llvm.org
Mon Jun 30 12:37:51 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 90da61634a4accc9869b4e1cb1ac3736158c33e6
      https://github.com/llvm/llvm-project/commit/90da61634a4accc9869b4e1cb1ac3736158c33e6
  Author: Slava Zakharin <szakharin at nvidia.com>
  Date:   2025-06-30 (Mon, 30 Jun 2025)

  Changed paths:
    M flang/lib/Optimizer/Transforms/AddAliasTags.cpp
    A flang/test/Transforms/tbaa-for-local-vars.fir
    M flang/test/Transforms/tbaa-with-dummy-scope2.fir

  Log Message:
  -----------
  [flang] Use outermost fir.dummy_scope for TBAA of local allocations. (#146006)

This change only matters when MLIR function inlining kicks in,
and I am still just experimenting with this.

The added LIT test shows the particular example where the current
TBAA assignment is incorrect:
```
  subroutine bar(this)
    ...
  end subroutine bar
  function foo() result(res)
    type(t) :: res
    call bar(res)
  end function foo
  subroutine test(arg)
    ! %0 = fir.alloca !fir.type<_QMmTt{x:f32}> {bindc_name = ".result"}
    type(t) :: var
    var = foo()
    ! fir.save_result foo's result to %0 (temp-alloca)
    ! fir.declare %0 {uniq_name = ".tmp.func_result"}
    ! load from %0 -> store into var
    arg = var%x
  end subroutine test
```

One way for FIR inlining to handle `foo()` call is to substitute
all uses of the `res` alloca (inside `foo`) with uses of the temp-alloca
(inside `test`). This means that the temp-alloca is then used
by the code inside bar (e.g. to store something into it).
After the inlining, the innermost dominating fir.dummy_scope
for `fir.declare %0` is the one from `bar`. If we use this scope
for assigning TBAA to the load from temp-alloca, then it will be
in the same TBAA tree as the stores into `this` inside `bar`.
The load and the stores will have different sub-trees, because
`this` is a dummy argument, and temp-alloca is a local allocation.
So they will appear as non-conflicting while they are accessing
the same memory.

This change makes sure that all local allocations always
use the outermost scope.



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