mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-04 09:11:43 +00:00
Add new transformation: // (~A | ~B) == (~(A & B))
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5738 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0cec701eb2
commit
a27231acc0
@ -446,6 +446,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
|
|||||||
Instruction *Or = BinaryOperator::create(Instruction::Or, Op0NotVal,
|
Instruction *Or = BinaryOperator::create(Instruction::Or, Op0NotVal,
|
||||||
Op1NotVal,I.getName()+".demorgan",
|
Op1NotVal,I.getName()+".demorgan",
|
||||||
&I);
|
&I);
|
||||||
|
WorkList.push_back(Or);
|
||||||
return BinaryOperator::createNot(Or);
|
return BinaryOperator::createNot(Or);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,15 +471,25 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||||||
if (RHS->isAllOnesValue())
|
if (RHS->isAllOnesValue())
|
||||||
return ReplaceInstUsesWith(I, Op1);
|
return ReplaceInstUsesWith(I, Op1);
|
||||||
|
|
||||||
if (Value *X = dyn_castNotVal(Op0)) // ~A | A == -1
|
Value *Op0NotVal = dyn_castNotVal(Op0);
|
||||||
if (X == Op1)
|
Value *Op1NotVal = dyn_castNotVal(Op1);
|
||||||
return ReplaceInstUsesWith(I,
|
|
||||||
ConstantIntegral::getAllOnesValue(I.getType()));
|
|
||||||
|
|
||||||
if (Value *X = dyn_castNotVal(Op1)) // A | ~A == -1
|
if (Op1 == Op0NotVal) // ~A | A == -1
|
||||||
if (X == Op0)
|
return ReplaceInstUsesWith(I,
|
||||||
return ReplaceInstUsesWith(I,
|
ConstantIntegral::getAllOnesValue(I.getType()));
|
||||||
ConstantIntegral::getAllOnesValue(I.getType()));
|
|
||||||
|
if (Op0 == Op1NotVal) // A | ~A == -1
|
||||||
|
return ReplaceInstUsesWith(I,
|
||||||
|
ConstantIntegral::getAllOnesValue(I.getType()));
|
||||||
|
|
||||||
|
// (~A | ~B) == (~(A & B)) - Demorgan's Law
|
||||||
|
if (Op0NotVal && Op1NotVal && isOnlyUse(Op0) && isOnlyUse(Op1)) {
|
||||||
|
Instruction *And = BinaryOperator::create(Instruction::And, Op0NotVal,
|
||||||
|
Op1NotVal,I.getName()+".demorgan",
|
||||||
|
&I);
|
||||||
|
WorkList.push_back(And);
|
||||||
|
return BinaryOperator::createNot(And);
|
||||||
|
}
|
||||||
|
|
||||||
return Changed ? &I : 0;
|
return Changed ? &I : 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user