I am not sure if I have to create a separate topic for the next discussion, because it seems related. Please let me know if you think it should be extracted.
I am trying to improve the disambiguation for “call” operations (fir.call in particular) such that some memory accesses can be optimized across the calls, e.g.:
%v1 = memref.load %a[%i]
fir.call @callee()
%v2 = memref.load %a[%i]
fir.call operation does not implement MemoryEffectsOpInterface currently, so it follows the conservatively safe paths within AliasAnalysis:getModRef and in any other analysis that tries to get the side-effects for an operation.
In general, most of the calls are still opaque and we do not know anything about them (i.e. they may affect any resource addresable or non-addresable in any way), but for some of them we know exactly which memory they can affect (e.g. some Fortran IO runtime functions only read through their pointer arguments and otherwise address only “inaccessible” memory).
So I would like to be able to report some exact side effects for some instances of fir.call and report “unknown” side effects for other instances.
I think there are two approaches:
- Make
MemoryEffectsOpInterfaceoptional so thatisa<MemoryEffectsOpInterface>(callOp)may returntrueorfalsedepending on the operation’s instance. - Model “unknown” side effects using a “cover-all-memory” resource that overlaps with any other resource (regardless of addressability).
I drafted both approaches #1 and #2, and I lean toward 1 in the end.
Approach 2 has a slight drawback because it requires that all analyses are aware about AnyResource resource and may need to treat it explicitly. Checking isa<MemoryEffectsOpInterface>(callOp) for deducing “unknown” effects seems to be an established approach already, so approach 1 wins in this regard.
I guess there may be arguments to apply both PRs at the same time, if AnyResource may have some uses regardless of the optionally side effects for call (or any) operations.
Please let me know if any of the proposed approaches seems reasonable to you. Thank you!