If a function accesses a global constant array of constants--in my case a constant array of function pointers, and does NOT reference this array via a function argument (it instead directly references this global), is this enough to disallow the application of the readnone attribute to the function in question? Thanks in advance Garrison
Garrison Venn wrote:> If a function accesses a global constant array of constants--in my case > a constant array of function pointers, and does NOT reference this > array via a function argument (it instead directly references this global), > is this enough to disallow the application of the readnone attribute to the > function in question?A function is readnone if it doesn't access any mutable state, so reading a constant global is fine. (Incidentally, it may even contain stores to constants because any such operation is undefined.) I was sure that I remember "opt -functionattrs" being taught to do this, but I just tried it out and it doesn't. This is a missed optz'n opportunity, testcase: @x = constant i32 0 define void @foo() { load i32* @x ret void } is only marked readonly when it should be readnone. Could I interest you in fixing that? :) Nick
Nick Lewycky wrote:> I was sure that I remember "opt -functionattrs" being taught to do this, > but I just tried it out and it doesn't. This is a missed optz'n > opportunity, testcase: > > @x = constant i32 0 > define void @foo() { > load i32* @x > ret void > } > > is only marked readonly when it should be readnone. Could I interest you > in fixing that? :)Never mind, it's because the default AA is no-aa, which answers no to everything. "opt -basicaa -functionattrs" gets this testcase right (and the one that stores, too!) Nick