diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-16 01:20:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-16 01:20:27 +0000 |
commit | c317d39887940e63b040d6461d305129adb698ad (patch) | |
tree | 5463e1631569a6e6441c1077c6a57c1b038a3bbc | |
parent | a783c02749eb8aa1bc79248a622fd34faebe1b71 (diff) |
Implement Transforms/InstCombine/xor.ll:test19
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11490 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 773441f538..15c8945089 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -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 |