[flang-commits] [flang] [flang] AliasAnalysis: Handle fir.load on fir.alloca (PR #117785)

Joel E. Denny via flang-commits flang-commits at lists.llvm.org
Wed Feb 5 08:47:46 PST 2025


================
@@ -522,6 +546,12 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v,
         .Case<fir::AllocaOp, fir::AllocMemOp>([&](auto op) {
           // Unique memory allocation.
           type = SourceKind::Allocate;
+          // If there's no DeclareOp, then we need to get the pointer attribute
+          // from the type.  TODO: That case occurs in our test suite
+          // (alias-analysis-2.fir), but does flang currently generate such
+          // code?
+          if (isPointerReference(ty))
+            attributes.set(Attribute::Pointer);
----------------
jdenny-ornl wrote:

> OK. I was given a few days to go deeper into this.

Sounds good.  Thanks.

> I am not sure I agree with your conclusion on T3 but T4 is an issue.

We can return to T3 after discussing the path forward for T4.

> T4 is a new test, so not a regression but would be if added before these changes. And that's what I am trying to say.

Whether a behavior is tested upstream does not indicate whether breaking it is a regression.  @jeanPerier has specifically [expressed concern](https://github.com/llvm/llvm-project/pull/94242#pullrequestreview-2248272387) about lack of test coverage for Flang's alias analysis.

> These changes could really be broken up into separate PRs. It would help considerably with this review.

I'm fine to split it up, but I'm striving to land the PRs in an order that doesn't leave anything important broken for an indefinite amount of time.  If we agree T3 or T4 reveals a regression, then we need to figure out what PR to propose as a *parent* of this PR.

> Also, as I am looking into this more, would you like us to considering `fir.alloca !fir.ptr<T>` as non-data and `!fir.ptr<T>` as data?

Yes, if `fir.alloca !fir.ptr<T>` and thus `!fir.ref<!fir.ptr<T>>` are important cases and essentially represent the same Fortran concepts as `fir.alloca !fir.box<!fir.ptr<T>>` and `!fir.ref<!fir.box<!fir.ptr<T>>>`, then that seems reasonable to me.

I tried that approach in this PR originally with C1, but my inability to make Flang produce those cases from Fortran means my implementation is not well tested, and I'm not confident I've handled all cases.

https://github.com/llvm/llvm-project/pull/117785


More information about the flang-commits mailing list