diff --git a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp index 66b4b84998801..26bab9e2974cb 100644 --- a/flang/lib/Optimizer/Transforms/AddAliasTags.cpp +++ b/flang/lib/Optimizer/Transforms/AddAliasTags.cpp @@ -50,6 +50,15 @@ static llvm::cl::opt static llvm::cl::opt enableLocalAllocs( "local-alloc-tbaa", llvm::cl::init(false), llvm::cl::Hidden, llvm::cl::desc("Add TBAA tags to local allocations. UNSAFE.")); +// This is **known unsafe** (miscompare in Fujitsu: Fortran/0614/0614_0005.f +// for ARM). Detailed analysis of the root cause: +// https://github.com/llvm/llvm-project/issues/141928 +// The code is kept so that these may be tried with new benchmarks to see if +// this is worth fixing in the future. This flag has no effect unless +// enableLocalAllocs is set +static llvm::cl::opt enablePtrLocalAllocs( + "ptr-local-alloc-tbaa", llvm::cl::init(false), llvm::cl::Hidden, + llvm::cl::desc("Add TBAA tags to local pointer allocations. UNSAFE.")); namespace { @@ -287,6 +296,9 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op, << "WARN: unknown defining op for SourceKind::Allocate " << *op << "\n"); } else if (source.isPointer()) { + // Do not add tbaa tags for local pointers unless flag is set + if (!enablePtrLocalAllocs) + return; LLVM_DEBUG(llvm::dbgs().indent(2) << "Found reference to allocation at " << *op << "\n"); tag = state.getFuncTreeWithScope(func, scopeOp).targetDataTree.getTag(); diff --git a/flang/test/Transforms/tbaa3.fir b/flang/test/Transforms/tbaa3.fir index 28ff8f7c5fa83..5f446cd3fa20e 100644 --- a/flang/test/Transforms/tbaa3.fir +++ b/flang/test/Transforms/tbaa3.fir @@ -1,5 +1,6 @@ // 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 +// RUN: fir-opt --fir-add-alias-tags --local-alloc-tbaa --ptr-local-alloc-tbaa %s | FileCheck --check-prefixes=ALL,PTR-LOCAL %s // Test AddAliasTagsPass creating sub-tree for TARGET/POINTER variables. @@ -298,7 +299,8 @@ module { %83 = fir.array_coor %80(%82) %c1 : (!fir.box>>, !fir.shift<1>, index) -> !fir.ref // real, pointer :: localp(:) // DEFAULT-NOT: fir.store{{.*}}tbaa -// LOCAL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref +// LOCAL-NOT: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref +// PTR-LOCAL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %83 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %84 = fir.load %27 : !fir.ref>>>