On Mon, Oct 26, 2020 at 01:46:52PM +0100, Richard Biener wrote: > On Mon, Oct 26, 2020 at 10:59 AM Stefan Schulze Frielinghaus via Gcc > <gcc@gcc.gnu.org> wrote: > > > > I'm trying to detect loops of the form > > > > while (*x != y) > > ++x; > > > > which mimic the behaviour of function rawmemchr. Note, the size of *x is > > not > > necessarily one byte. Thus ultimately I would like to detect such loops and > > replace them with calls to builtins rawmemchr8, rawmemchr16, rawmemchr32 if > > they are implemented in the backend: > > > > x = __builtin_rawmemchr16(x, y); > > > > I'm wondering whether there is a particular place in order to detect such > > loop > > patterns. For example, in the loop distribution pass GCC recognizes loops > > which mimic the behavior of memset, memcpy, memmove and replaces them with > > calls to their corresponding builtins, respectively. The pass and in > > particular partitioning of statements depends on whether a statement is used > > outside of a partition or not. This works perfectly fine for loops which > > implement the mentioned mem* operations since their result is typically > > ignored. However, the result of a rawmemchr function is/should never be > > ignored. Therefore, such loops are currently recognized as having a > > reduction > > which makes an implementation into the loop distribution pass not straight > > forward to me. > > > > Are there other places where you would detect such loops? Any comments? > > loop distribution is the correct pass to look at. You're simply the first to > recognize a reduction pattern. And yes, you'll likely need some generic > adjustments to the code to handle this.
Ok, then I will have a look into this pass. Thanks for clarifying this! Cheers, Stefan > > Richard. > > > Cheers, > > Stefan