[llvm-bugs] [Bug 46260] New: Using builtin_assume to optimize pointer "ptr + size / sizeof(Struct)" does not work

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 9 14:43:48 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=46260

            Bug ID: 46260
           Summary: Using builtin_assume to optimize pointer "ptr + size /
                    sizeof(Struct)" does not work
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mvels at google.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Background: for some vector logic, I attempted to minimize the code for keeping
the distance for some 'begin' vs 'end' span.

i.e.:
void SomeFunction() {
  size_type size = byte_size(begin_, end_);
  begin_ = grow_or_something(begin_, ....);
  end_ = add_byte_size(begin_, size);
}

auto byte_size(S* begin, S* end) {
    return (end - begin) * sizeof(S);
}

auto add_byte_size(S* begin, size_t n) {
    __builtin_assume((n % sizeof(S)) == 0);
    return begin + n / sizeof(S);
}

The 'add_byte_size()' method refuses to do the raw add, despite my 'assume this
is a multiple of sizeof(S)'. The only think that works (reliably) is cast it
through intptr, which I'd prefer not to. (especially as the real code works
with pointer traits / pointer types making it even more verbose / boilerplate.

See examples / attempts / what works at https://gcc.godbolt.org/z/94Upor

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200609/a9d6f19e/attachment.html>


More information about the llvm-bugs mailing list