[llvm-dev] Deterministic function return attribute
László Radnai via llvm-dev
llvm-dev at lists.llvm.org
Thu Aug 13 04:23:36 PDT 2020
I'm interested in what attributes in LLVM mean, specifically how to
say that the result is always the same for the given input parameters.
The main thing would be to merge two calls with the same parameters
when the function is declared but not defined. (just like two stores).
I'll call this property mergability.
%1 := call @test(%0)
%2 := call @test(%0)
and the optimization would be something like (%2).replaceUsesWith((%1)).
I think it's related to speculatable & readnone in LLVM, (if I
understood well, it's the same as GCC's __attribute__((pure)), but I'm
not sure whether there are edgecases where the mergability is not
I've seen somewhere that maybe malloc has these attributes, but it
surely cannot be merged. This is because there is memory read/written
that cannot be seen by LLVM (which is accepted by readnone). This
would be a counter-example.
So my question is:
Is mergability equivalent to the readnone+speculatable attribute?
If not, is there some attribute that should help?
And also, does malloc have (or rather, could malloc have) these attributes?
More information about the llvm-dev