[llvm-bugs] [Bug 46279] New: Unnecessary branch with -fstrict-enums

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jun 11 06:00:45 PDT 2020


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

            Bug ID: 46279
           Summary: Unnecessary branch with -fstrict-enums
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: jmuizelaar at mozilla.com
                CC: llvm-bugs at lists.llvm.org

This code:

#include <stdlib.h>
enum Foo {
    A,
    B,
    C,
};

Foo foo(Foo* data) {
    Foo k = data[1];
    if (k > Foo::C) {
        exit(3);
    }
    return k;
}

compiles with -fstrict-enums to:

foo(Foo*):                            # @foo(Foo*)
        pushq   %rax
        movl    4(%rdi), %eax
        cmpl    $3, %eax
        je      .LBB0_2
        popq    %rcx
        retq
.LBB0_2:
        movl    $3, %edi
        callq   exit

It should be possible to elide the call to exit()

Interestingly enough, without -fstrict-enums the je becomes jge so LLVM has
some idea about what's going on.

-- 
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/20200611/cef150a1/attachment.html>


More information about the llvm-bugs mailing list