mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-28 06:58:19 +00:00
Fold away one multiply in instcombine. This would normally be caught in
reassociate anyways, but they could be generated during instcombine's run. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46683 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9d3e5d476c
commit
b6eabff169
@ -2123,6 +2123,30 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
|
|||||||
if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2)))
|
if (Instruction *R = AssociativeOpt(I, AddMaskingAnd(C2)))
|
||||||
return R;
|
return R;
|
||||||
|
|
||||||
|
// W*X + Y*Z --> W * (X+Z) iff W == Y
|
||||||
|
if (I.getType()->isInteger()) {
|
||||||
|
Value *W, *X, *Y, *Z;
|
||||||
|
if (match(LHS, m_Mul(m_Value(W), m_Value(X))) &&
|
||||||
|
match(RHS, m_Mul(m_Value(Y), m_Value(Z)))) {
|
||||||
|
if (W != Y) {
|
||||||
|
if (W == Z) {
|
||||||
|
std::swap(Y, Z);
|
||||||
|
} else if (Y == X) {
|
||||||
|
std::swap(W, X);
|
||||||
|
} else if (X == Z) {
|
||||||
|
std::swap(Y, Z);
|
||||||
|
std::swap(W, X);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (W == Y) {
|
||||||
|
Value *NewAdd = InsertNewInstBefore(BinaryOperator::createAdd(X, Z,
|
||||||
|
LHS->getName()), I);
|
||||||
|
return BinaryOperator::createMul(W, NewAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
|
if (ConstantInt *CRHS = dyn_cast<ConstantInt>(RHS)) {
|
||||||
Value *X = 0;
|
Value *X = 0;
|
||||||
if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
|
if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
|
||||||
|
Loading…
Reference in New Issue
Block a user