[LLVMbugs] [Bug 1976] New: instcombine doesn't fold x*y+x*z to x*(y+z)

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat Feb 2 20:41:40 PST 2008


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

           Summary: instcombine doesn't fold x*y+x*z to x*(y+z)
           Product: libraries
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Scalar Optimizations
        AssignedTo: nicholas at mxc.ca
        ReportedBy: nicholas at mxc.ca
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=1369)
 --> (http://llvm.org/bugs/attachment.cgi?id=1369)
proposed patch (a little ugly)

Instcombine should be able to fold:

define i8 @test1(i8 %x, i8 %y, i8 %z) {
  %A = mul i8 %x, %y
  %B = mul i8 %x, %z
  %C = add i8 %A, %B
  ret i8 %C
}

into this:

define i8 @test2(i8 %x, i8 %y, i8 %z) {
  %A = add i8 %y, %z
  %B = mul i8 %x, %A
  ret i8 %B
}

It currently implements this only when %y and %z are ConstantInt. That's wrong,
this transformation works in general.

Patch attached. (Note that we shouldn't remove the existing "X*C1 + X*C2 --> X
* (C1+C2)" trafo because it also does shift-left combining.)


-- 
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