[llvm-bugs] [Bug 30907] New: Expression can be expanded to fold two constant integer multiplies into one.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 3 15:25:39 PDT 2016


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

            Bug ID: 30907
           Summary: Expression can be expanded to fold two constant
                    integer multiplies into one.
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: simon.hosie at arm.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Clang apparently cannot see that these are equivalent:

uint32_t f0(uint32_t x, uint32_t y) {
  static const uint64_t k0 = 0x12345678, k1 = 0x87654321, k2 =
0x0123456789abcdef;
  return (uint32_t)(k2 * (k0 * x + k1 * y) >> 32);
}

uint32_t f1(uint32_t x, uint32_t y) {
  static const uint64_t k0 = 0x12345678, k1 = 0x87654321, k2 =
0x0123456789abcdef;
  return (uint32_t)((k2 * k0 * x + k2 * k1 * y) >> 32);
}

clang -O3 -S -o- test.c

f0() gets three multiplies on 64-bit targets, while f1() gets two.

I guess it's possible that f0 could turn out faster on some hardware because it
needs only one full 64x64 multiply (along with two 64x32 multiplies).  If the
compiler knows that then maybe it should factorise rather than expand.

-- 
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/20161103/559a7877/attachment.html>


More information about the llvm-bugs mailing list