[llvm-bugs] [Bug 45864] New: Failure to optimize out check for (x * x) == 0 when (x < -1 || x > 1)

via llvm-bugs llvm-bugs at lists.llvm.org
Sun May 10 09:00:28 PDT 2020


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

            Bug ID: 45864
           Summary: Failure to optimize out check for (x * x) == 0 when (x
                    < -1 || x > 1)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: gabravier at gmail.com
                CC: llvm-bugs at lists.llvm.org

#ifdef __clang__
#define assume __builtin_assume
#else

inline void assume(bool b)
{
    if (!b)
        __builtin_unreachable();
}

#endif

bool f(int x, bool cond)
{
    assume(x > 1 || x < -1);
    if (cond)
        return (x * x) == 0;
    else
        return false;
}

This can be optimized to `return false;`. GCC does this transformation, but
Clang does not.

-- 
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/20200510/4017dba6/attachment.html>


More information about the llvm-bugs mailing list