[llvm-bugs] [Bug 46876] New: 'dereferenceable' not treated as implying 'nonnull'?

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 28 13:09:49 PDT 2020


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

            Bug ID: 46876
           Summary: 'dereferenceable' not treated as implying 'nonnull'?
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: richard-llvm at metafoo.co.uk
                CC: llvm-bugs at lists.llvm.org

In this C++ testcase:

int f(int &v, int k) {
    int a = 0;
    for (int n = 0; n != k; ++n) {
        a += v;
    }
    return a;
}

... LLVM is able to optimize away the branch and produce 'return k * v;'

In this similar C testcase:

int f(int arr[static 1], int k) {
    int a = 0;
    for (int n = 0; n != k; ++n) {
        a += *arr;
    }
    return a;
}

... LLVM leaves behind the branch.

The only relevant difference between the IR emitted for the two testcases
appears to be that in the C++ case we emit the 'v' parameter as 'nonnull
dereferenceable(4)', whereas in the C case we emit the 'arr' parameter as only
'dereferenceable(4)', not 'nonnull'.

But 'dereferenceable(N)' is supposed to imply 'nonnull' in the default address
space, so that presumably shouldn't make any difference!

-- 
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/20200728/0a859228/attachment.html>


More information about the llvm-bugs mailing list