My auto-simplifier noticed that ((X/Y)*Y)/Y occurs several times in SPEC
authorDuncan Sands <baldrick@free.fr>
Fri, 28 Jan 2011 16:51:11 +0000 (16:51 +0000)
committerDuncan Sands <baldrick@free.fr>
Fri, 28 Jan 2011 16:51:11 +0000 (16:51 +0000)
commit593faa53fa6d89841e601cc4571d143a6a05f0b4
tree0b119c1a312e445ae9c0ece500f9e574daf47818
parentabcae24d991844ac6ac33b773b1007e2e901575c
My auto-simplifier noticed that ((X/Y)*Y)/Y occurs several times in SPEC
benchmarks, and that it can be simplified to X/Y.  (In general you can only
simplify (Z*Y)/Y to Z if the multiplication did not overflow; if Z has the
form "X/Y" then this is the case).  This patch implements that transform and
moves some Div logic out of instcombine and into InstructionSimplify.
Unfortunately instcombine gets in the way somewhat, since it likes to change
(X/Y)*Y into X-(X rem Y), so I had to teach instcombine about this too.
Finally, thanks to the NSW/NUW flags, sometimes we know directly that "Z*Y"
does not overflow, because the flag says so, so I added that logic too.  This
eliminates a bunch of divisions and subtractions in 447.dealII, and has good
effects on some other benchmarks too.  It seems to have quite an effect on
tramp3d-v4 but it's hard to say if it's good or bad because inlining decisions
changed, resulting in massive changes all over.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124487 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Analysis/InstructionSimplify.h
lib/Analysis/InstructionSimplify.cpp
lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
test/Transforms/InstCombine/2008-11-20-DivMulRem.ll
test/Transforms/InstSimplify/2010-12-20-Reassociate.ll