[llvm-bugs] [Bug 37404] New: Missed optimization: fmax(-a, -b) -> -fmin(a, b)

via llvm-bugs llvm-bugs at lists.llvm.org
Thu May 10 02:04:47 PDT 2018


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

            Bug ID: 37404
           Summary: Missed optimization: fmax(-a, -b) -> -fmin(a, b)
           Product: libraries
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: m-takahiro at jp.fujitsu.com
                CC: llvm-bugs at lists.llvm.org

I compiled the following code by clang (tags/RELEASE_600/final 327104).
Option is '-Ofast -march=native'

#include <math.h>
double foo(double a, double b) {
  return fmax(-a, -b);
}

Generated IRs are as follows.

; Function Attrs: nounwind readnone uwtable
define double @foo(double, double) local_unnamed_addr #0 {
  %3 = fsub fast double -0.000000e+00, %0
  %4 = fsub fast double -0.000000e+00, %1
  %5 = tail call fast double @llvm.maxnum.f64(double %3, double %4)
  ret double %5
}

I think the above IRs can be simplified like the following.

; Function Attrs: nounwind readnone uwtable
define double @foo(double, double) local_unnamed_addr #0 {
  %2 = tail call fast double @llvm.minnum.f64(double %0, double %1)
  %3 = fsub fast double -0.000000e+00, %2
  ret double %3
}

-- 
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/20180510/3ca4a5b5/attachment.html>


More information about the llvm-bugs mailing list