Skip to content

Commit e125dcd

Browse files
committed
[flang] Support fir.pack_array in FIR alias analysis.
`fir.pack_array` is just a pass-through op for the process of finding the source in FIR alias analysis (as defined in #127147).
1 parent af7c8c4 commit e125dcd

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
542542
v = op->getOperand(0);
543543
defOp = v.getDefiningOp();
544544
})
545+
.Case<fir::PackArrayOp>([&](auto op) {
546+
// The packed array is not distinguishable from the original
547+
// array, so skip PackArrayOp and track further through
548+
// the array operand.
549+
v = op.getArray();
550+
defOp = v.getDefiningOp();
551+
})
545552
.Case<fir::BoxAddrOp>([&](auto op) {
546553
v = op->getOperand(0);
547554
defOp = v.getDefiningOp();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test alias analysis queries for dummy arguments wired
2+
// through fir.pack_array.
3+
// fir.pack_array is a pass-through operation for FIR alias analysis.
4+
// RUN: fir-opt %s --test-fir-alias-analysis -split-input-file --mlir-disable-threading 2>&1 | FileCheck %s
5+
6+
// CHECK: test1_y(1)#0 <-> test1_x(1)#0: NoAlias
7+
func.func @_QFtest1(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "x"}, %arg1: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "y"}) {
8+
%c1 = arith.constant 1 : index
9+
%0 = fir.dummy_scope : !fir.dscope
10+
%1 = fir.pack_array %arg0 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
11+
%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>>)
12+
%3 = fir.pack_array %arg1 heap whole : (!fir.box<!fir.array<?xf32>>) -> !fir.box<!fir.array<?xf32>>
13+
%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>
15+
%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>
17+
hlfir.assign %6 to %7 : f32, !fir.ref<f32>
18+
fir.unpack_array %3 to %arg1 heap : !fir.box<!fir.array<?xf32>>
19+
fir.unpack_array %1 to %arg0 heap : !fir.box<!fir.array<?xf32>>
20+
return
21+
}

0 commit comments

Comments
 (0)