[llvm-bugs] [Bug 45694] New: Inconsistent optimization of bit twiddling function

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 27 02:43:17 PDT 2020


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

            Bug ID: 45694
           Summary: Inconsistent optimization of bit twiddling function
           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

unsigned r1(unsigned a, unsigned b, unsigned mask)
{
    return a ^ ((a ^ b) & mask);
}

unsigned r2(unsigned a, unsigned b, unsigned mask)
{
    return (~mask & a) | (b & mask);
}

On x86, if `-mbmi` is on, `r1` is translated to `r2`, and then `andn` is used
to generate faster code. If `-mbmi` is off, this optimization does not occur.
Presumably, this would mean that then `r1` is faster than `r2`. I would thus
suggest that in those cases `r2` be optimized to `r1`.

With `-mbmi` : https://godbolt.org/z/CrJboc
Without `-mbmi` : https://godbolt.org/z/kg3vH6

-- 
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/20200427/112c5cea/attachment-0001.html>


More information about the llvm-bugs mailing list