[LLVMbugs] [Bug 9895] New: missed optz'n on uadd.with.overflow

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue May 10 18:06:36 PDT 2011


http://llvm.org/bugs/show_bug.cgi?id=9895

           Summary: missed optz'n on uadd.with.overflow
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nlewycky at google.com
                CC: llvmbugs at cs.uiuc.edu


This is a missed optimization I found doing a superoptimizer run, and it occurs
plenty often in our code:

; Input: 00:07:07:12:-0001:01:-0005:-0005:2b:35:0e:05:-0009:-0004:37:35:2b
declare {i8, i1} @llvm.uadd.with.overflow.i8(i8, i8)
define i1 @test(i8 %X, i8 %Y) {
  %x = sub i8 %X, %Y
  %A = icmp eq i8 %X, %Y
  %y = select i1 %A, i8 1, i8 %x

  %B = call {i8, i1} @llvm.uadd.with.overflow.i8(i8 %y, i8 %x)
  %C = extractvalue {i8, i1} %B, 0
  %D = extractvalue {i8, i1} %B, 1
  %E = select i1 %D, i8 -1, i8 %C
  %F = icmp eq i8 %E, 0
  ret i1 %F
}

It always returns false, but the optimizer doesn't understand the correlation
between %y and %C. If it did, then we would get stuck on this second missed
optzn:

define i1 @test(i8 %X, i8 %Y) nounwind readnone {
  %x = sub i8 %X, %Y
  %A = icmp eq i8 %X, %Y  ; implies %x = 0
  %y = select i1 %A, i8 1, i8 %x  ; actually select i1 %A, i8 1, i8 0
  %ZZZ = sub i8 0, %x
  %F1 = icmp eq i8 %y, %ZZZ
  ret i1 %F1
}

If we do that substitution manually, we get down to this:

define i1 @test(i8 %X, i8 %Y) nounwind readnone {
  %A = icmp eq i8 %X, %Y
  %y = zext i1 %A to i8
  %x1 = sub i8 %Y, %X
  %F1 = icmp eq i8 %y, %x1
  ret i1 %F1
}

which is a correlated expr problem.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list