Skip to content

instcombine doesn't fold x*y+x*z to x*(y+z) #2348

@nlewycky

Description

@nlewycky
Bugzilla Link 1976
Resolution FIXED
Resolved on Feb 03, 2008 01:43
Version trunk
OS All
Attachments proposed patch (a little ugly)

Extended Description

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 "XC1 + XC2 --> X * (C1+C2)" trafo because it also does shift-left combining.)

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzilla

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions