@@ -108,12 +108,11 @@ 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 () << " AliasAnalysis::alias\n " ;
111+ LLVM_DEBUG (llvm::dbgs () << " \n " ; llvm::dbgs () << " AliasAnalysis::alias\n " ;
112112 llvm::dbgs () << " lhs: " << lhs << " \n " ;
113113 llvm::dbgs () << " lhsSrc: " << lhsSrc << " \n " ;
114114 llvm::dbgs () << " rhs: " << rhs << " \n " ;
115- llvm::dbgs () << " rhsSrc: " << rhsSrc << " \n " ;
116- llvm::dbgs () << " \n " ;);
115+ llvm::dbgs () << " rhsSrc: " << rhsSrc << " \n " ;);
117116
118117 // Indirect case currently not handled. Conservatively assume
119118 // it aliases with everything
@@ -122,43 +121,22 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
122121 return AliasResult::MayAlias;
123122 }
124123
125- // If we have reached the same source but comparing box reference against
126- // data we are not comparing apples-to-apples. The 2 cannot alias.
127- if ((lhsSrc.origin .u == rhsSrc.origin .u ) &&
128- lhsSrc.isData () != rhsSrc.isData ()) {
129- return AliasResult::NoAlias;
130- }
131-
132124 if (lhsSrc.kind == rhsSrc.kind ) {
133125 if (lhsSrc.origin == rhsSrc.origin ) {
126+ LLVM_DEBUG (llvm::dbgs ()
127+ << " aliasing because same source kind and origin\n " );
134128 if (approximateSource)
135129 return AliasResult::MayAlias;
136130 return AliasResult::MustAlias;
137131 }
138132
139133 // Two host associated accesses may overlap due to an equivalence.
140- if (lhsSrc.kind == SourceKind::HostAssoc)
141- return AliasResult::MayAlias;
142-
143- // TARGET/POINTER arguments may alias.
144- if (lhsSrc.isTargetOrPointer () && rhsSrc.isTargetOrPointer () &&
145- lhsSrc.isData () == rhsSrc.isData ())
134+ if (lhsSrc.kind == SourceKind::HostAssoc) {
135+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of host association\n " );
146136 return AliasResult::MayAlias;
147-
148- // Box for POINTER component inside an object of a derived type
149- // may alias box of a POINTER object, as well as boxes for POINTER
150- // components inside two objects of derived types may alias.
151- if ((lhsSrc.isRecordWithPointerComponent () && rhsSrc.isTargetOrPointer ()) ||
152- (rhsSrc.isRecordWithPointerComponent () && lhsSrc.isTargetOrPointer ()) ||
153- (lhsSrc.isRecordWithPointerComponent () &&
154- rhsSrc.isRecordWithPointerComponent ()))
155- return AliasResult::MayAlias;
156-
157- return AliasResult::NoAlias;
137+ }
158138 }
159139
160- assert (lhsSrc.kind != rhsSrc.kind && " memory source kinds must be different" );
161-
162140 Source *src1, *src2;
163141 if (lhsSrc.kind < rhsSrc.kind ) {
164142 src1 = &lhsSrc;
@@ -190,17 +168,21 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
190168
191169 // Dummy TARGET/POINTER argument may alias with a global TARGET/POINTER.
192170 if (src1->isTargetOrPointer () && src2->isTargetOrPointer () &&
193- src1->isData () == src2->isData ())
171+ src1->isData () == src2->isData ()) {
172+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of target or pointer\n " );
194173 return AliasResult::MayAlias;
174+ }
195175
196176 // Box for POINTER component inside an object of a derived type
197177 // may alias box of a POINTER object, as well as boxes for POINTER
198178 // components inside two objects of derived types may alias.
199179 if ((src1->isRecordWithPointerComponent () && src2->isTargetOrPointer ()) ||
200180 (src2->isRecordWithPointerComponent () && src1->isTargetOrPointer ()) ||
201181 (src1->isRecordWithPointerComponent () &&
202- src2->isRecordWithPointerComponent ()))
182+ src2->isRecordWithPointerComponent ())) {
183+ LLVM_DEBUG (llvm::dbgs () << " aliasing because of pointer components\n " );
203184 return AliasResult::MayAlias;
185+ }
204186
205187 return AliasResult::NoAlias;
206188}
@@ -306,17 +288,15 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v) {
306288 breakFromLoop = true ;
307289 })
308290 .Case <fir::LoadOp>([&](auto op) {
309- if (followBoxData && mlir::isa<fir::BaseBoxType>(op.getType ())) {
310- // For now, support the load of an argument or fir.address_of
311- // TODO: generalize to all operations (in particular fir.alloca and
312- // fir.allocmem)
313- auto def = getOriginalDef (op.getMemref ());
314- if (isDummyArgument (def) ||
315- def.template getDefiningOp <fir::AddrOfOp>()) {
316- v = def;
317- defOp = v.getDefiningOp ();
318- return ;
319- }
291+ // If the load is from a leaf source, return the leaf. Do not track
292+ // through indirections otherwise.
293+ // TODO: At support to fir.alloca and fir.allocmem
294+ auto def = getOriginalDef (op.getMemref ());
295+ if (isDummyArgument (def) ||
296+ def.template getDefiningOp <fir::AddrOfOp>()) {
297+ v = def;
298+ defOp = v.getDefiningOp ();
299+ return ;
320300 }
321301 // No further tracking for addresses loaded from memory for now.
322302 type = SourceKind::Indirect;
0 commit comments