public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC] [PR tree-optimization/92539] Optimize away tests against invalid pointers
@ 2024-03-10 21:03 Jeff Law
  2024-03-10 21:05 ` Andrew Pinski
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff Law @ 2024-03-10 21:03 UTC (permalink / raw)
  To: gcc-patches

Here's a potential approach to fixing PR92539, a P2 -Warray-bounds false 
positive triggered by loop unrolling.

As I speculated a couple years ago, we could eliminate the comparisons 
against bogus pointers.  Consider:

>   <bb 8> [local count: 30530247]:
>   if (last_12 != &MEM <const char> [(void *)"aa" + 3B])
>     goto <bb 9>; [54.59%]
>   else
>     goto <bb 12>; [45.41%]


That's a valid comparison as ISO allows us to generate, but not 
dereference, a pointer one element past the end of the object.

But +4B is a bogus pointer.  So given an EQ comparison against that 
pointer we could always return false and for NE always return true.

VRP and DOM seem to be the most natural choices for this kind of 
optimization on the surface.  However DOM is actually not viable because 
the out-of-bounds pointer warning pass is run at the end of VRP.  So 
we've got to take care of this prior to the end of VRP.



I haven't done a bootstrap or regression test with this.  But if it 
looks reasonable I can certainly push on it further. I have confirmed it 
does eliminate the tests and shuts up the bogus warning.

The downside is this would also shut up valid warnings if user code did 
this kind of test.

Comments/Suggestions?

Jeff

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-03-12  0:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-10 21:03 [RFC] [PR tree-optimization/92539] Optimize away tests against invalid pointers Jeff Law
2024-03-10 21:05 ` Andrew Pinski
2024-03-10 21:09   ` Jeff Law
2024-03-11  3:19     ` Andrew Pinski
2024-03-11  7:46     ` Richard Biener
2024-03-11  7:57       ` Richard Biener
2024-03-12  0:18       ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).