[llvm-bugs] [Bug 35725] New: Missed optimization with int overflow

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 21 14:25:31 PST 2017


            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: unassignedclangbugs at nondot.org
          Reporter: zamazan4ik at tut.by
                CC: llvm-bugs at 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

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

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/20171221/fa2c016e/attachment.html>

More information about the llvm-bugs mailing list