[flang-commits] [flang] [flang] AliasAnalysis: More formally define and distinguish between data and non-data (PR #91020)
Renaud Kauffmann via flang-commits
flang-commits at lists.llvm.org
Mon May 6 15:07:58 PDT 2024
================
@@ -97,29 +117,20 @@ AliasResult AliasAnalysis::alias(Value lhs, Value rhs) {
// Indirect case currently not handled. Conservatively assume
// it aliases with everything
- if (lhsSrc.kind > SourceKind::Direct || rhsSrc.kind > SourceKind::Direct) {
+ if (lhsSrc.kind >= SourceKind::Indirect ||
+ rhsSrc.kind >= SourceKind::Indirect) {
return AliasResult::MayAlias;
}
- // SourceKind::Direct is set for the addresses wrapped in a global boxes.
- // ie: fir.global @_QMpointersEp : !fir.box<!fir.ptr<f32>>
- // Though nothing is known about them, they would only alias with targets or
- // pointers
- bool directSourceToNonTargetOrPointer = false;
- if (lhsSrc.u != rhsSrc.u || lhsSrc.kind != rhsSrc.kind) {
- if ((lhsSrc.kind == SourceKind::Direct && !rhsSrc.isTargetOrPointer()) ||
- (rhsSrc.kind == SourceKind::Direct && !lhsSrc.isTargetOrPointer()))
- directSourceToNonTargetOrPointer = true;
- }
-
- if (lhsSrc.kind == SourceKind::Direct ||
- rhsSrc.kind == SourceKind::Direct) {
- if (!directSourceToNonTargetOrPointer)
- return AliasResult::MayAlias;
+ // If we have reached the same source but comparing box reference against
+ // data we are not comparing apples-to-apples. The 2 cannot alias.
+ if ((lhsSrc.origin.u == rhsSrc.origin.u) &&
+ lhsSrc.isData() != rhsSrc.isData()) {
----------------
Renaud-K wrote:
We have `isRecordWithPointerComponent` which is a pretty big hammer. It does not distinguish between data and non-data, so %x and %2 will alias. Also in this case, there are indirect loads. The source of %5 is %3 and we do not get passed this load because it is not a source. I will add the test. There is room for improvement. For instance `isRecordWithPointerComponent` even says that x and y alias.
https://github.com/llvm/llvm-project/pull/91020
More information about the flang-commits
mailing list