[llvm-bugs] [Bug 50167] New: Avoid unnecessary widening

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Apr 29 03:29:09 PDT 2021


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

            Bug ID: 50167
           Summary: Avoid unnecessary widening
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: llvm-bugs at lists.llvm.org

>From Reddit:

void scale(uint8_t *__restrict dst, const uint8_t *__restrict src1) {
    for(int i=0; i<64; ++i) {
        int v = src1[i] * 3;

        if (v > 255)
            v = 255;

        dst[i] = (uint8_t)v;
    }
}

"Clang manages a decent attempt and recognizes that it can reduce the
multiplication to adds, but fails to stay at byte width and ends up widening
all the way to int, which seriously hurts throughput. It seems that the
optimizer failed to track value ranges properly as it could have stayed at
short (16-bit), and the narrowing also has an unnecessary clamp that the
packuswb instruction already provides."

https://gcc.godbolt.org/z/85f6YYEq3

-- 
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/20210429/77640399/attachment.html>


More information about the llvm-bugs mailing list