public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/67809] New: Empty pointer-chasing loops aren't optimized out
@ 2015-10-01 20:47 matt at godbolt dot org
  2015-10-02  9:29 ` [Bug middle-end/67809] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: matt at godbolt dot org @ 2015-10-01 20:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67809

            Bug ID: 67809
           Summary: Empty pointer-chasing loops aren't optimized out
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matt at godbolt dot org
  Target Milestone: ---

The following code:

```
struct Foo {
  Foo *next; 

  void release() {
    Foo *tmp = 0;
    for (Foo *it = next; it; it = tmp) {
      tmp = it->next;
    }
  }
};

void test(Foo &f) { f.release(); }
```

Results in pointer-chasing code when compiled at -O3:

```
test(Foo&):
        mov     rax, QWORD PTR [rdi]
        test    rax, rax
        je      .L1
.L3:
        mov     rax, QWORD PTR [rax]
        test    rax, rax
        jne     .L3
.L1:
        rep ret
```

clang and icc both optimize this to a single ret. e.g. https://goo.gl/saN4XC vs
https://goo.gl/LeUGn0

Would be nice for this loop to go away completely. For context, this was in
code I added to use ASAN_POISON_MEMORY_REGION() around a pooled allocator upon
free of a list (each node was poisoned individually). Without
-fsanitize=address I was expecting the loop to entirely vanish, but the
pointer-chase was still done.


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

end of thread, other threads:[~2021-08-28 23:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-01 20:47 [Bug middle-end/67809] New: Empty pointer-chasing loops aren't optimized out matt at godbolt dot org
2015-10-02  9:29 ` [Bug middle-end/67809] " rguenth at gcc dot gnu.org
2015-10-02  9:52 ` glisse at gcc dot gnu.org
2021-06-12 12:30 ` gareth@ignition-web.co.uk
2021-08-28 23:52 ` pinskia at gcc dot gnu.org

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).