diff options
author | Chris Lattner <sabre@nondot.org> | 2006-05-05 06:39:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-05-05 06:39:07 +0000 |
commit | 6fc205fc446050a434e49e7cfcac89bb5d4435b1 (patch) | |
tree | af0bc08f0552b4d1674110f69240dc6755c6e770 | |
parent | a0771b802050d4d014893d4322364005742052e5 (diff) | |
download | external_llvm-6fc205fc446050a434e49e7cfcac89bb5d4435b1.zip external_llvm-6fc205fc446050a434e49e7cfcac89bb5d4435b1.tar.gz external_llvm-6fc205fc446050a434e49e7cfcac89bb5d4435b1.tar.bz2 |
Implement InstCombine/cast.ll:test29
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28126 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index dfd568c..2c8f6ed 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2640,6 +2640,19 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { } } + // fold (and (cast A), (cast B)) -> (cast (and A, B)) + if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) { + if (CastInst *Op1C = dyn_cast<CastInst>(Op1)) + if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() && + Op0C->getOperand(0)->getType()->isIntegral()) { + Instruction *NewOp = BinaryOperator::createAnd(Op0C->getOperand(0), + Op1C->getOperand(0), + I.getName()); + InsertNewInstBefore(NewOp, I); + return new CastInst(NewOp, I.getType()); + } + } + return Changed ? &I : 0; } @@ -2865,6 +2878,20 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { } } } + + // fold (or (cast A), (cast B)) -> (cast (or A, B)) + if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) { + if (CastInst *Op1C = dyn_cast<CastInst>(Op1)) + if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() && + Op0C->getOperand(0)->getType()->isIntegral()) { + Instruction *NewOp = BinaryOperator::createOr(Op0C->getOperand(0), + Op1C->getOperand(0), + I.getName()); + InsertNewInstBefore(NewOp, I); + return new CastInst(NewOp, I.getType()); + } + } + return Changed ? &I : 0; } @@ -3030,6 +3057,19 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (Instruction *R = AssociativeOpt(I, FoldSetCCLogical(*this, RHS))) return R; + // fold (xor (cast A), (cast B)) -> (cast (xor A, B)) + if (CastInst *Op0C = dyn_cast<CastInst>(Op0)) { + if (CastInst *Op1C = dyn_cast<CastInst>(Op1)) + if (Op0C->getOperand(0)->getType() == Op1C->getOperand(0)->getType() && + Op0C->getOperand(0)->getType()->isIntegral()) { + Instruction *NewOp = BinaryOperator::createXor(Op0C->getOperand(0), + Op1C->getOperand(0), + I.getName()); + InsertNewInstBefore(NewOp, I); + return new CastInst(NewOp, I.getType()); + } + } + return Changed ? &I : 0; } |