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

            Bug ID: 35725
           Summary: Missed optimization with int overflow
           Product: clang
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangb...@nondot.org
          Reporter: zamazan...@tut.by
                CC: llvm-bugs@lists.llvm.org

clang(trunk) with '-O3 -std=c++17 -ffast-math' for this:

#include <limits>

int test(int x)
{
    if(x == std::numeric_limits<int>::max())
    {
        return x+1;
    }
    return 42;
}

generates this:

test(int): # @test(int)
  lea ecx, [rdi + 1]
  cmp edi, 2147483647
  mov eax, 42
  cmove eax, ecx
  ret


But branch with condition is UB, so you can just delete it and simply return
42.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to