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: unassignedb...@nondot.org
          Reporter: lebedev...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to