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

            Bug ID: 42456
           Summary: [InstCombine] Dropping pointless masking before shift
           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/cuuf0P
https://rise4fun.com/Alive/PcZk

int bad(unsigned input, unsigned len) {
    unsigned shamt = (32 - len);
    unsigned diff = input >> shamt;
    return (int(diff) << shamt) >> shamt;
}
int good(unsigned input, unsigned len) {
    return int(input) >> (32 - len);
}

Name: 
  %sub = sub i32 32, %len
  %zz = shl i32 -1, %sub
  %shl = and i32 %zz, %input
  %r = ashr i32 %shl, %sub
=>
  %r = ashr i32 %input, %sub

-- 
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