1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Implement Transforms/InstCombine/xor.ll:test19

llvm-svn: 11490
This commit is contained in:
Chris Lattner 2004-02-16 01:20:27 +00:00
parent 3bef114bbe
commit 71154f0931

View File

@ -1002,15 +1002,26 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
return Changed ? &I : 0;
}
// XorSelf - Implements: X ^ X --> 0
struct XorSelf {
Value *RHS;
XorSelf(Value *rhs) : RHS(rhs) {}
bool shouldApply(Value *LHS) const { return LHS == RHS; }
Instruction *apply(BinaryOperator &Xor) const {
return &Xor;
}
};
Instruction *InstCombiner::visitXor(BinaryOperator &I) {
bool Changed = SimplifyCommutative(I);
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
// xor X, X = 0
if (Op0 == Op1)
// xor X, X = 0, even if X is nested in a sequence of Xor's.
if (Instruction *Result = AssociativeOpt(I, XorSelf(Op1))) {
assert(Result == &I && "AssociativeOpt didn't work?");
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
}
if (ConstantIntegral *RHS = dyn_cast<ConstantIntegral>(Op1)) {
// xor X, 0 == X