----- Original Message ----- > From: "Aaron Ballman" <[email protected]> > To: "Hal Finkel" <[email protected]> > Cc: "Michael M Kuperstein" <[email protected]>, "Richard Smith" > <[email protected]>, "llvm cfe" > <[email protected]>, > [email protected] > Sent: Monday, March 23, 2015 12:00:39 PM > Subject: Re: [PATCH] Have HasSideEffects() return false for > __attribute__((const)) functions > > On Mon, Mar 23, 2015 at 12:44 PM, Hal Finkel <[email protected]> wrote: > > ----- Original Message ----- > >> From: "Aaron Ballman" <[email protected]> > >> To: [email protected] > >> Cc: "Michael M Kuperstein" <[email protected]>, > >> "Richard Smith" <[email protected]>, "Hal Finkel" > >> <[email protected]>, "llvm cfe" <[email protected]> > >> Sent: Monday, March 23, 2015 11:38:02 AM > >> Subject: Re: [PATCH] Have HasSideEffects() return false for > >> __attribute__((const)) functions > >> > >> On Mon, Mar 23, 2015 at 12:33 PM, [email protected] > >> <[email protected]> > >> wrote: > >> > In http://reviews.llvm.org/D8548#145253, @mkuper wrote: > >> > > >> >> I think PureAttr isn't strong enough. > >> >> > >> >> char foo(char *a) > >> >> { > >> >> > >> >> return *a; > >> >> > >> >> } > >> >> > >> >> is pure, but isn't side-effect free. > >> > > >> > > >> > Loads are not considered side effects currently, however. This > >> > works fine: > >> > > >> > void bar(int *i) { > >> > __builtin_assume(*i > 0); > >> > } > >> > > >> > and, thus, my recommendation ;) > >> > >> Some loads are side-effecting though, such as volatile loads: > >> > >> int foo(volatile int *a) { > >> return *a; > >> } > >> > >> Can that be marked __attribute__((pure))? Or can pure access a > >> volatile global variable? > > > > I think that the answer is no, but only by indirect inference. The > > GCC docs say: > > > > [from GCC docs] > > Many functions have no effects except the return value and their > > return value depends only on the parameters and/or global > > variables. Such a function can be subject to common subexpression > > elimination and loop optimization just as an arithmetic operator > > would be. > > [end from GCC docs] > > > > and since volatile loads often cannot be CSE'd, I suspect they're > > meant to be excluded. What do you think? > > I'm not overly familiar with __attribute__((pure)), but what you say > seems logical. Looking at the GCC docs a bit more closely, it also > says: "Interesting non-pure functions are functions with infinite > loops or those depending on volatile memory or other system resource, > that may change between two consecutive calls (such as feof in a > multithreading environment). "
Indeed; good point. > > So I think it might be safe to do this for __attribute__((pure)) as > well. Cool; let's do it! -Hal > > ~Aaron > > > > > -Hal > > > >> > >> ~Aaron > >> > >> > > >> > > >> > http://reviews.llvm.org/D8548 > >> > > >> > EMAIL PREFERENCES > >> > http://reviews.llvm.org/settings/panel/emailpreferences/ > >> > > >> > > >> > > > > -- > > Hal Finkel > > Assistant Computational Scientist > > Leadership Computing Facility > > Argonne National Laboratory > -- Hal Finkel Assistant Computational Scientist Leadership Computing Facility Argonne National Laboratory _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
