[llvm-bugs] [Bug 42389] New: InstCombine: lshr + "sext" => ashr canonicalization

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jun 25 12:42:08 PDT 2019


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

            Bug ID: 42389
           Summary: InstCombine: lshr + "sext" => ashr canonicalization
           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

I have not triaged yet what folds are missing, but this gigantic fold is
missing:
https://godbolt.org/z/E9-txU

int bad(unsigned input, unsigned len) {
    unsigned diff = input >> (32 - 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;
}
int good(unsigned input, unsigned len) {
    return int(input) >> (32 - len);
}

https://rise4fun.com/Alive/l3k

Name: ashr
  %o3 = sub i32 32, %nbits
  %o4 = lshr i32 %x, %o3
  %o5 = add i32 %nbits, -1
  %o6 = lshr i32 %o4, %o5
  %o7 = icmp eq i32 %o6, 0
  %o8 = shl i32 1, %nbits
  %o9 = select i1 %o7, i32 0, i32 %o8
  %r = sub i32 %o4, %o9
=>
  %n0 = sub i32 32, %nbits
  %r = ashr i32 %x, %n0

I'm seeing this in real code.

-- 
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/20190625/9d8eb3f6/attachment.html>


More information about the llvm-bugs mailing list