Skip to content

Commit 804a4b9

Browse files
committed
Rebased to commit 83f065d
1 parent 60d6c94 commit 804a4b9

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

flang/include/flang/Optimizer/Analysis/AliasAnalysis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct AliasAnalysis {
6464
// subroutine test()
6565
// use top
6666
// a(1) = 1
67+
// end subroutine
6768
// -------------------------------------------------
6869
//
6970
// flang-new -fc1 -emit-fir test.f90 -o test.fir

flang/lib/Optimizer/Analysis/AliasAnalysis.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
108108
auto lhsSrc = getSource(lhs);
109109
auto rhsSrc = getSource(rhs);
110110
bool approximateSource = lhsSrc.approximateSource || rhsSrc.approximateSource;
111-
LLVM_DEBUG(llvm::dbgs() << "\n"; llvm::dbgs() << "AliasAnalysis::alias\n";
111+
LLVM_DEBUG(llvm::dbgs() << "\nAliasAnalysis::alias\n";
112112
llvm::dbgs() << " lhs: " << lhs << "\n";
113113
llvm::dbgs() << " lhsSrc: " << lhsSrc << "\n";
114114
llvm::dbgs() << " rhs: " << rhs << "\n";
@@ -173,8 +173,9 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
173173
return AliasResult::MayAlias;
174174
}
175175

176-
// POINTER components may alias with POINTER objects,
177-
// as well as other POINTER components
176+
// Box for POINTER component inside an object of a derived type
177+
// may alias box of a POINTER object, as well as boxes for POINTER
178+
// components inside two objects of derived types may alias.
178179
if ((src1->isRecordWithPointerComponent() && src2->isTargetOrPointer()) ||
179180
(src2->isRecordWithPointerComponent() && src1->isTargetOrPointer()) ||
180181
(src1->isRecordWithPointerComponent() &&

flang/test/Analysis/AliasAnalysis/alias-analysis-9.fir

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
// CHECK-DAG: x#0 <-> y#0: MayAlias
2222

2323
// TODO: y is not a pointer object and therefore does not alias with the x%next component.
24+
// Also assigning x to y would not modify x.next
2425
// CHECK-DAG: y#0 <-> xnext1#0: MayAlias
2526
// CHECK-DAG: y#0 <-> xnext2#0: MayAlias
2627

27-
// Pointer components may alias with pointer objects,
28-
// as well as other pointer components
28+
// We need to catch the fact that assigning y to x will modify xnext.
29+
// The only side-effect between the 2 loads of x.next is the assignment to x,
30+
// therefore x needs to alias with x.next to prevent the loads from being merged.
2931
// CHECK-DAG: x#0 <-> xnext1#0: MayAlias
3032
// CHECK-DAG: x#0 <-> xnext2#0: MayAlias
3133

0 commit comments

Comments
 (0)