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

Reply via email to