Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions flang/lib/Optimizer/Transforms/AddAliasTags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ static llvm::cl::opt<bool>
static llvm::cl::opt<bool> 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<bool> enablePtrLocalAllocs(
"ptr-local-alloc-tbaa", llvm::cl::init(false), llvm::cl::Hidden,
llvm::cl::desc("Add TBAA tags to local pointer allocations. UNSAFE."));

namespace {

Expand Down Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion flang/test/Transforms/tbaa3.fir
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -298,7 +299,8 @@ module {
%83 = fir.array_coor %80(%82) %c1 : (!fir.box<!fir.ptr<!fir.array<?xf32>>>, !fir.shift<1>, index) -> !fir.ref<f32>
// real, pointer :: localp(:)
// DEFAULT-NOT: fir.store{{.*}}tbaa
// LOCAL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref<f32>
// LOCAL-NOT: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref<f32>
// PTR-LOCAL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref<f32>
fir.store %cst to %83 : !fir.ref<f32>
// ALL-NOT: fir.load{{.*}}tbaa
%84 = fir.load %27 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
Expand Down
Loading