[llvm-bugs] [Bug 48524] New: Failure to optimize simple bitwise pattern

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 15 13:47:04 PST 2020


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

            Bug ID: 48524
           Summary: Failure to optimize simple bitwise pattern
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

int f1(int n)
{
    return n - (((n > 63) ? n : 63) & -64);
}

This can be optimized to `return (n <= 63) ? n : (n & 63);` (and presumably the
same optimization should be doable with other powers of 2).

PS: I found this optimization while looking at how this :

int f1(int n)
{
    while (n >= 64)
        n -= 64;

    return n;
}

is optimized. LLVM outputs the first example I gave here, while GCC outputs the
optimization I gave here.

-- 
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/20201215/5e247ea8/attachment.html>


More information about the llvm-bugs mailing list