[llvm-bugs] [Bug 35717] New: Regression for three way min/max

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 21 09:06:21 PST 2017


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

            Bug ID: 35717
           Summary: Regression for three way min/max
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: david.green at arm.com
                CC: llvm-bugs at lists.llvm.org

This is a regression that came in with rL320749. We have some code with three
way min/max that is now doing a lot worse than it did previously. The most
basic for I could come up with is this:

int test(int xc, int xm, int xy)
{
  int xk;
  if (xc < xm)
    xk = xc < xy ? xc : xy;
  else
    xk = xm < xy ? xm : xy;
  return xk;
}

This used to come out as (roughly "min(min(a,b),c)"):
define i32 @test(i32 %xc, i32 %xm, i32 %xy) {
entry:
  %cmp = icmp slt i32 %xc, %xm
  %xm.sink15 = select i1 %cmp, i32 %xc, i32 %xm
  %cmp2 = icmp slt i32 %xm.sink15, %xy
  %cond6 = select i1 %cmp2, i32 %xm.sink15, i32 %xy
  ret i32 %cond6
}

But now ends up with extra selects (roughly "min(min(a,b), min(b,c))"):
define i32 @test(i32 %xc, i32 %xm, i32 %xy) {
entry:
  %cmp = icmp slt i32 %xc, %xm
  %cmp1 = icmp slt i32 %xc, %xy
  %cond = select i1 %cmp1, i32 %xc, i32 %xy
  %cmp2 = icmp slt i32 %xm, %xy
  %cond6 = select i1 %cmp2, i32 %xm, i32 %xy
  %xk.0 = select i1 %cmp, i32 %cond, i32 %cond6
  ret i32 %xk.0
}

The original case came from a cmy conversion, where the values were i8 (not
i32) so there is a number of zext and trunc's making things more messy. They
are also inverted (subtracted from 255). It runs especially worse on our small
thumb1 cores.

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


More information about the llvm-bugs mailing list