[llvm-bugs] [Bug 43564] New: [InstCombine] Failure to recognize sign bit test if the high bit extract is followed by trunc

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Oct 4 05:47:56 PDT 2019


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

            Bug ID: 43564
           Summary: [InstCombine] Failure to recognize sign bit test if
                    the high bit extract is followed by trunc
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: lebedev.ri at gmail.com
                CC: llvm-bugs at lists.llvm.org

https://godbolt.org/z/hzDvD_

Given
int bad(unsigned input, unsigned len) {
    unsigned diff = input & ((1 << len)-1);
    // If the first bit is 1 we need to turn this into a negative number
    if (diff >> (len - 1))
        diff -= (1 << len);
    return diff;
}
we get
  %5 = icmp slt i32 %0, 0

But for 
int bad2(unsigned long input, unsigned len) {
    unsigned diff = input >> (64 - len);
    // If the first bit is 1 we need to turn this into a negative number
    if (diff >> (len - 1))
        diff -= (1 << len);
    return diff;
}
we no longer recognize it, and remain with
  %7 = add i32 %1, -1
  %8 = lshr i32 %6, %7
  %9 = icmp eq i32 %8, 0

-- 
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/20191004/9d8c7106/attachment-0001.html>


More information about the llvm-bugs mailing list