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: unassignedclangb...@nondot.org
          Reporter: mv...@google.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to