Exploit distributive laws (eg: And distributes over Or, Mul over Add, etc) in a
authorDuncan Sands <baldrick@free.fr>
Tue, 23 Nov 2010 14:23:47 +0000 (14:23 +0000)
committerDuncan Sands <baldrick@free.fr>
Tue, 23 Nov 2010 14:23:47 +0000 (14:23 +0000)
commit5057f381418ddc8c96699c40479ead993cd62e7b
treee8737928b5fd38869ede79b36e7987bd51989a9e
parent0cc5b1f60e02716cac617959d88d4c412fdb3154
Exploit distributive laws (eg: And distributes over Or, Mul over Add, etc) in a
fairly systematic way in instcombine.  Some of these cases were already dealt
with, in which case I removed the existing code.  The case of Add has a bunch of
funky logic which covers some of this plus a few variants (considers shifts to be
a form of multiplication), which I didn't touch.  The simplification performed is:
A*B+A*C -> A*(B+C).  The improvement is to do this in cases that were not already
handled [such as A*B-A*C -> A*(B-C), which was reported on the mailing list], and
also to do it more often by not checking for "only one use" if "B+C" simplifies.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120024 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombine.h
lib/Transforms/InstCombine/InstCombineAddSub.cpp
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/2010-11-23-Distributed.ll [new file with mode: 0644]