[flang-commits] [flang] [flang] Use fir.declare/fir.dummy_scope for TBAA tags attachments. (PR #92472)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Wed May 22 03:42:57 PDT 2024
================
@@ -52,6 +52,38 @@ TBAABuilder::TBAABuilder(MLIRContext *context, bool applyTBAA,
bool forceUnifiedTree)
: enableTBAA(applyTBAA && !disableTBAA),
trees(/*separatePerFunction=*/perFunctionTBAATrees && !forceUnifiedTree) {
+ // TODO: the TBAA tags created here are rooted in the root scope
+ // of the enclosing function. This does not work best with MLIR inlining.
+ // A better approach is to root them according to the scopes they belong to
+ // and that were used by AddAliasTagsPass to create TBAA tags before
+ // the CodeGen. For example:
+ // subroutine caller(a, b, ptr)
+ // real, target :: a(:), b(:)
+ // integer, pointer :: ptr(:)
+ // call callee(a, b, ptr)
+ // end
+ // subroutine callee(a, b, ptr)
+ // real :: a(:), b(:)
+ // integer, pointer :: ptr(:)
+ // do i=...
+ // a(ptr(i)) = b(ptr(i))
+ // end do
+ // end
+ //
+ // When callee is inlined, the dummy arguments 'a' and 'b' will
+ // be rooted in TBAA tree corresponding to the `call callee` call site,
+ // saying that the references to 'a' and 'b' cannot alias each other.
+ // These tags will be created by AddAliasTagsPass, but it will not be able
+ // to create any tags for 'ptr' references.
+ // During the CodeGen, we create 'any data access' tags for the
+ // 'ptr' acceses. If they are rooted within the root scope of `caller`,
+ // they end up in a different TBAA tree with the 'a' and 'b' access
+ // tags, so 'ptr', 'a' and 'b' references MayAlias. Moreover,
+ // the box access of 'ptr' will also be in a different TBAA tree
+ // with 'a' and 'b' tags, meaning they can also alias.
+ // This will prevent LLVM vectorization even with memory conflict checks.
+ // It seems that we'd better move all TBAA tags assignment to
+ // AddAliasTagsPass, which can at least rely on the dummy arguments scopes.
----------------
tblah wrote:
The problem is that box loads and stores are implicit in FIR. There is no operation to tag until after codegen.
I would be happy to see an end to this so that most uses of `!fir.box<>` become `!fir.ref<!fir.box<>>`. It makes IR a bit more verbose but I think it would make it a lot more obvious at a glance where we are generating unnecessary pointer nesting.
https://github.com/llvm/llvm-project/pull/92472
More information about the flang-commits
mailing list