Files
Slava Zakharin 90da61634a [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.
2025-06-30 12:37:30 -07:00
..