Skip to content

Commit edaf9d8

Browse files
committed
Cray pointer/pointee can alias with anything.
1 parent df5a2fe commit edaf9d8

File tree

3 files changed

+54
-4
lines changed

3 files changed

+54
-4
lines changed

flang/include/flang/Optimizer/Analysis/TBAAForest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ struct TBAATree {
9696
// "any access"
9797
// |
9898
// |- "descriptor member"
99-
// |- "any data access"
99+
// |- "any data access" <--- Cray pointer/pointee accesses
100100
// |
101101
// |- "dummy arg data"
102102
// |

flang/lib/Optimizer/Transforms/AddAliasTags.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,16 @@ void AddAliasTagsPass::runOnAliasInterface(fir::FirAliasTagOpInterface op,
687687
}
688688

689689
mlir::LLVM::TBAATagAttr tag;
690-
// TBAA for dummy arguments
691-
if (enableDummyArgs &&
692-
source.kind == fir::AliasAnalysis::SourceKind::Argument) {
690+
// Cray pointer/pointee is a special case. These might alias with any data.
691+
if (source.isCrayPointerOrPointee()) {
692+
LLVM_DEBUG(llvm::dbgs().indent(2)
693+
<< "Found reference to Cray pointer/pointee at " << *op << "\n");
694+
mlir::LLVM::TBAATypeDescriptorAttr anyDataDesc =
695+
state.getFuncTreeWithScope(func, scopeOp).anyDataTypeDesc;
696+
tag = mlir::LLVM::TBAATagAttr::get(anyDataDesc, anyDataDesc, /*offset=*/0);
697+
// TBAA for dummy arguments
698+
} else if (enableDummyArgs &&
699+
source.kind == fir::AliasAnalysis::SourceKind::Argument) {
693700
LLVM_DEBUG(llvm::dbgs().indent(2)
694701
<< "Found reference to dummy argument at " << *op << "\n");
695702
std::string name = getFuncArgName(llvm::cast<mlir::Value>(source.origin.u));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: fir-opt --fir-add-alias-tags %s | FileCheck %s
2+
3+
// Fortran source:
4+
// subroutine test()
5+
// real :: a, b
6+
// pointer(p, a)
7+
// p = loc(b)
8+
// b = 2
9+
// end subroutine
10+
11+
// CHECK: #[[TBAA_ROOT:.*]] = #llvm.tbaa_root<id = "Flang function root _QPtest">
12+
// CHECK-NEXT: #[[ANY_ACCESS:.*]] = #llvm.tbaa_type_desc<id = "any access", members = {<#[[TBAA_ROOT]], 0>}>
13+
// CHECK-NEXT: #[[ANY_DATA:.*]] = #llvm.tbaa_type_desc<id = "any data access", members = {<#[[ANY_ACCESS]], 0>}>
14+
// CHECK-NEXT: #[[ANY_DATA_TAG:.*]] = #llvm.tbaa_tag<base_type = #[[ANY_DATA]], access_type = #[[ANY_DATA]], offset = 0>
15+
// CHECK-NEXT: #[[ALLOCATED_DATA:.*]] = #llvm.tbaa_type_desc<id = "allocated data", members = {<#[[ANY_DATA]], 0>}>
16+
// CHECK-NEXT: #[[B:.*]] = #llvm.tbaa_type_desc<id = "allocated data/_QFtestEb", members = {<#[[ALLOCATED_DATA]], 0>}>
17+
// CHECK-NEXT: #[[B_TAG:.*]] = #llvm.tbaa_tag<base_type = #[[B]], access_type = #[[B]], offset = 0>
18+
19+
module attributes {dlti.dl_spec = #dlti.dl_spec<!llvm.ptr<270> = dense<32> : vector<4xi64>, !llvm.ptr<271> = dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i8 = dense<[8, 32]> : vector<2xi64>, i16 = dense<[16, 32]> : vector<2xi64>, i64 = dense<64> : vector<2xi64>, i128 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", "dlti.mangling_mode" = "e", "dlti.legal_int_widths" = array<i32: 32, 64>, "dlti.stack_alignment" = 128 : i64, "dlti.function_pointer_alignment" = #dlti.function_pointer_alignment<32, function_dependent = true>>, fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"} {
20+
// CHECK-LABEL: func.func @_QPtest()
21+
func.func @_QPtest() {
22+
%cst = arith.constant 2.000000e+00 : f32
23+
%0 = fir.alloca !fir.box<!fir.ptr<f32>>
24+
%1 = fir.dummy_scope : !fir.dscope
25+
%2 = fir.alloca i64 {bindc_name = "p", uniq_name = "_QFtestEp"}
26+
%3 = fir.declare %2 {fortran_attrs = #fir.var_attrs<cray_pointer>, uniq_name = "_QFtestEp"} : (!fir.ref<i64>) -> !fir.ref<i64>
27+
%4 = fir.alloca f32 {bindc_name = "b", uniq_name = "_QFtestEb"}
28+
%5 = fir.declare %4 {uniq_name = "_QFtestEb"} : (!fir.ref<f32>) -> !fir.ref<f32>
29+
%6 = fir.declare %0 {fortran_attrs = #fir.var_attrs<pointer, cray_pointee>, uniq_name = "_QFtestEa"} : (!fir.ref<!fir.box<!fir.ptr<f32>>>) -> !fir.ref<!fir.box<!fir.ptr<f32>>>
30+
%7 = fir.zero_bits !fir.ptr<f32>
31+
%8 = fir.embox %7 : (!fir.ptr<f32>) -> !fir.box<!fir.ptr<f32>>
32+
fir.store %8 to %6 : !fir.ref<!fir.box<!fir.ptr<f32>>>
33+
// Descriptor tagged in codegen
34+
// CHECK: fir.store %{{.*}} to %{{.*}} : !fir.ref<!fir.box<!fir.ptr<f32>>
35+
%9 = fir.convert %5 : (!fir.ref<f32>) -> i64
36+
fir.store %9 to %3 : !fir.ref<i64>
37+
// CHECK: fir.store {{.*}} to {{.*}} {tbaa = [#[[ANY_DATA_TAG]]]} : !fir.ref<i64>
38+
fir.store %cst to %5 : !fir.ref<f32>
39+
// CHECK: fir.store {{.*}} to {{.*}} {tbaa = [#[[B_TAG]]]} : !fir.ref<f32>
40+
return
41+
}
42+
}
43+

0 commit comments

Comments
 (0)