[llvm-bugs] [Bug 35642] New: recognize min/max patterns as commutative

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 12 07:36:47 PST 2017


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

            Bug ID: 35642
           Summary: recognize min/max patterns as commutative
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: spatel+llvm at rotateright.com
                CC: llvm-bugs at lists.llvm.org

#include <algorithm>

int maxmax(int a, int b) {
  return std::max(a, b) - std::max(b, a);
}

Or as IR after -O2:

define i32 @_Z6maxmaxii(i32 %a, i32 %b) {
  %cmp1 = icmp slt i32 %a, %b
  %sel1 = select i1 %cmp1, i32 %b, i32 %a
  %cmp2 = icmp slt i32 %b, %a
  %sel2 = select i1 %cmp2, i32 %a, i32 %b
  %sub = sub nsw i32 %sel1, %sel2
  ret i32 %sub
}


https://godbolt.org/g/hG6HMR

I think early-cse needs to know that max is commutative. We can't easily
instcombine or instsimplify our way out of this.

-- 
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/20171212/b36c7ad2/attachment.html>


More information about the llvm-bugs mailing list