Skip to content

Commit 66ee2a2

Browse files
committed
Setting approximateSource to true for fir.pack_array.
1 parent e125dcd commit 66ee2a2

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
548548
// the array operand.
549549
v = op.getArray();
550550
defOp = v.getDefiningOp();
551+
approximateSource = true;
551552
})
552553
.Case<fir::BoxAddrOp>([&](auto op) {
553554
v = op->getOperand(0);

flang/test/Analysis/AliasAnalysis/alias-analysis-pack-array.fir

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,41 @@
33
// fir.pack_array is a pass-through operation for FIR alias analysis.
44
// RUN: fir-opt %s --test-fir-alias-analysis -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s
55

6-
// CHECK: test1_y(1)#0 <-> test1_x(1)#0: NoAlias
6+
// The two pointers referencing two different maybe repacked
7+
// versions of the original dummy arguments do not alias:
8+
// CHECK-DAG: test1_y_repack(1)#0 <-> test1_x_repack(1)#0: NoAlias
9+
// CHECK-DAG: test1_x_orig(1)#0 <-> test1_y_orig(1)#0: NoAlias
10+
11+
// Repacked dummy does not alias with another original dummy:
12+
// CHECK-DAG: test1_y_repack(1)#0 <-> test1_x_orig(1)#0: NoAlias
13+
// CHECK-DAG: test1_x_repack(1)#0 <-> test1_y_orig(1)#0: NoAlias
14+
15+
// Repacked dummy may alias with its original:
16+
// CHECK-DAG: test1_x_repack(1)#0 <-> test1_x_orig(1)#0: MayAlias
17+
// CHECK-DAG: test1_y_repack(1)#0 <-> test1_y_orig(1)#0: MayAlias
18+
19+
// Ideally, these should report MustAlias, but MayAlias
20+
// may work as well:
21+
// CHECK-DAG: test1_y_repack(1)#0 <-> test1_y_repack2(1)#0: MayAlias
22+
// CHECK-DAG: test1_x_repack(1)#0 <-> test1_x_repack2(1)#0: MayAlias
23+
24+
725
func.func @_QFtest1(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "y"}) {
826
%c1 = arith.constant 1 : index
927
%0 = fir.dummy_scope : !fir.dscope
1028
%1 = fir.pack_array %arg0 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1129
%2:2 = hlfir.declare %1 dummy_scope %0 {uniq_name = "_QFtest1Ex"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)
1230
%3 = fir.pack_array %arg1 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
1331
%4:2 = hlfir.declare %3 dummy_scope %0 {uniq_name = "_QFtest1Ey"} : (!fir.box<!fir.array<?xf32>>, !fir.dscope) -> (!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)
14-
%5 = hlfir.designate %4#0 (%c1) {test.ptr = "test1_y(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
32+
%5 = fir.box_addr %4#0 {test.ptr = "test1_y_repack(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
33+
%52 = fir.box_addr %4#0 {test.ptr = "test1_y_repack2(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
1534
%6 = fir.load %5 : !fir.ref<f32>
16-
%7 = hlfir.designate %2#0 (%c1) {test.ptr = "test1_x(1)"} : (!fir.box<!fir.array<?xf32>>, index) -> !fir.ref<f32>
35+
%7 = fir.box_addr %2#0 {test.ptr = "test1_x_repack(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
36+
%72 = fir.box_addr %2#0 {test.ptr = "test1_x_repack2(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
1737
hlfir.assign %6 to %7 : f32, !fir.ref<f32>
1838
fir.unpack_array %3 to %arg1 heap : !fir.box<!fir.array<?xf32>>
1939
fir.unpack_array %1 to %arg0 heap : !fir.box<!fir.array<?xf32>>
40+
%8 = fir.box_addr %arg0 {test.ptr = "test1_x_orig(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
41+
%9 = fir.box_addr %arg1 {test.ptr = "test1_y_orig(1)"} : (!fir.box<!fir.array<?xf32>>) -> !fir.ref<f32>
2042
return
2143
}

0 commit comments

Comments
 (0)