[Bug middle-end/32911] Function __attribute__ ((idempotent))
matthew at wil dot cx
gcc-bugzilla@gcc.gnu.org
Thu Aug 6 13:05:36 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32911
Matthew Wilcox <matthew at wil dot cx> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |matthew at wil dot cx
--- Comment #6 from Matthew Wilcox <matthew at wil dot cx> ---
I actually have a use for a real idempotent function, that is f(f(x)) == f(x).
I think it's different from the behaviour wanted here which is more of an
initialiser functionality.
The concrete example is Linux's compound_head() macro which takes a pointer to
a struct page and returns a pointer to a (potentially different) struct page.
A page is its own head, and calls to compound_head can be buried inside macros.
So I'd like gcc to know that given this program:
struct page *compound_head(struct page *) __attribute__((idempotent));
int g(struct page *page)
{
struct page *head = compound_head(page);
return page->refcount;
}
int f(struct page *page)
{
struct page *head = compound_head(page);
return g(head);
}
if it inlines g() into f(), it only needs to make one call to compound_head().
More information about the Gcc-bugs
mailing list