mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
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
This commit is contained in:
@@ -91,6 +91,8 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
||||
I.hasNoUnsignedWrap(), TD))
|
||||
return ReplaceInstUsesWith(I, V);
|
||||
|
||||
if (Instruction *NV = SimplifyDistributed(I)) // (A*B)+(A*C) -> A*(B+C)
|
||||
return NV;
|
||||
|
||||
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
|
||||
if (ConstantInt *CI = dyn_cast<ConstantInt>(RHSC)) {
|
||||
@@ -548,6 +550,9 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
|
||||
if (Op0 == Op1) // sub X, X -> 0
|
||||
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
|
||||
|
||||
if (Instruction *NV = SimplifyDistributed(I)) // (A*B)-(A*C) -> A*(B-C)
|
||||
return NV;
|
||||
|
||||
// If this is a 'B = x-(-A)', change to B = x+A. This preserves NSW/NUW.
|
||||
if (Value *V = dyn_castNegVal(Op1)) {
|
||||
BinaryOperator *Res = BinaryOperator::CreateAdd(Op0, V);
|
||||
|
Reference in New Issue
Block a user