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

            Bug ID: 45683
           Summary: Bad optimization of simple switch
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedb...@nondot.org
          Reporter: gabrav...@gmail.com
                CC: llvm-bugs@lists.llvm.org

int f(unsigned x)
{
    switch (x)
    {
        case 0:
            return 1;

        case 1:
            return 2;
    }
}

This gets optimized to some rather weird code (uses `sbb` on x86) when it could
just be optimized to `return x + 1`. See here for an example of the bad
generation : https://godbolt.org/z/2fQmpH

Maybe we could change the translation of `select` (as it is used in the IR this
translates to) in order to detect cases such as this and optimize them properly
?

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