This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix DSE not to consider calls as reads from function's body (PR target/77834)


On Fri, Nov 04, 2016 at 01:59:05PM +0100, Richard Biener wrote:
> > So like the variant patch I've just posted?
> 
> That doesn't handle
> 
> int __attribute__((const,noinline))
> foo ()
> {
>   return 1;
> }
> 
> int bar()
> {
>   *((int *)foo) + 4 = 2;
>   int ret = foo ();
>   *((int *)foo) + 4 = 1;
>   return ret;
> }
> 
> right?  patching foo to return 2, calling foo and then unpatching it?

If you mean *((int *)foo + 4) = rather than *((int *)foo) + 4,
then indeed it doesn't.  But GIMPLE optimizers remove that far before.
And I'm not sure if we want to pessimize code just for such hypothetical
cases; users can always add explicit optimization barriers;
or maybe just have a flag whether function text is writable
and disable that flag by default on non-bare metal?
Unless the function is in a writable section, if it isn't the kernel
or embedded target, most likely the function body won't be writable anyway.

Note I'm not sure that even without the patch we'd handle it at the
DSE/sched time - the thing is that the call's argument is a mem:QI,
so effectively represents just the first byte of the function.  So
if you stored to the first byte of the function, it might handle it
"right", but if you store 4 bytes at offset 4, nonoverlapping_memrefs_p
might still figure out that it is comparing a offset 4 4 byte memory
with offset 0 1 byte memory and tell they don't overlap.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]