[llvm-bugs] [Bug 44577] New: Missed optimization: clang does not infer from assumptions

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Jan 17 02:11:06 PST 2020


            Bug ID: 44577
           Summary: Missed optimization: clang does not infer from
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mafagafogigante at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

As of Clang 9.0.0, no inference is done based on __builtin_assume. I have
tested using "-std=c++17 -O2", but -O3 seems to do the same.

Example 1

  bool lessThan(int a, int b) {
      __builtin_assume(a < b);
      return a < b;

compiles into

  lessThan(int, int):
      mov     al, 1

as one would expect. If the assumption is negated (!(a < b)), the compiler will
optimize it to return 0. However, if the assumption is any of (a == b), (a >=
b), (a > b), or (a == b || a > b) a comparison is emitted.

Example 2

  bool lessThan(int a, int b, int c) {
      __builtin_assume(a < b);
      __builtin_assume(b < c);
      return a < c;

also requires a comparison, even though a < c can be inferred from the

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/20200117/b69604fe/attachment.html>

More information about the llvm-bugs mailing list