No, though depending on the type of
A may be replaced by a constant if the creator of that type allows for that specialization (for example if
A is not a materialized matrix at all but an iterator behaving like a matrix).
That transform again requires something like
Symbolics.jl and very specific semantics to be allowed to do (remember,
* is also just a regular function and may have side effects for some custom types).
Yes, a macro could be written to do this, since what you’re asking for is a syntactic transform (though that again is limited to code the macro sees -
@remove_redundancy sqrt(abs2(x)) could just spit out
@remove_redundancy f(x) with
f(x) = sqrt(abs2(x)) can not, since the macro can’t see “into”
Indeed they have, though that’s not what Tullio.jl is doing specifically. Those transforms are basically what
--fastmath is doing in some places.
Those transforms are few and far between and only applied if all involved behaviour can’t be distinguished (in terms of returned values). You’re probably thinking of the compiler replacing a naive sum over
1:n with the summation formula
(n*(n+1))/2 or even the resulting constant, if
n is known as well. Since they’re only applied if you can’t distinguish them, the results (in that sense) are “unmodified”. If I recall correctly, that specific transform is only applied for integer arguments, since floating point summation is not associative and you will get a different result.
This is not exclusive to LLVM, by the way - GCC does the same kinds of transforms, as do most sufficiently advanced compilers.