diff options
author | Chris Lattner <sabre@nondot.org> | 2004-07-06 07:38:18 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-07-06 07:38:18 +0000 |
commit | 23b47b6af962a67aa367211a512ecb0d9ee79e17 (patch) | |
tree | 6b25e6120664427c8e1cae405d29e3e77ce332cb /llvm/lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | eca92d3106c52b08022c51c8a8aa9d66c02fefb9 (diff) | |
download | bcm5719-llvm-23b47b6af962a67aa367211a512ecb0d9ee79e17.tar.gz bcm5719-llvm-23b47b6af962a67aa367211a512ecb0d9ee79e17.zip |
Implement rem.ll:test3
llvm-svn: 14640
Diffstat (limited to 'llvm/lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index be1111fbd53..4f6724ff52f 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1528,6 +1528,24 @@ Instruction *InstCombiner::visitSetCondInst(BinaryOperator &I) { // operand is a constant, simplify a bit. if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Op0)) { switch (BO->getOpcode()) { + case Instruction::Rem: + // If we have a signed (X % (2^c)) == 0, turn it into an unsigned one. + if (CI->isNullValue() && isa<ConstantSInt>(BO->getOperand(1)) && + BO->hasOneUse() && + cast<ConstantSInt>(BO->getOperand(1))->getValue() > 1) + if (unsigned L2 = + Log2(cast<ConstantSInt>(BO->getOperand(1))->getValue())) { + const Type *UTy = BO->getType()->getUnsignedVersion(); + Value *NewX = InsertNewInstBefore(new CastInst(BO->getOperand(0), + UTy, "tmp"), I); + Constant *RHSCst = ConstantUInt::get(UTy, 1ULL << L2); + Value *NewRem =InsertNewInstBefore(BinaryOperator::createRem(NewX, + RHSCst, BO->getName()), I); + return BinaryOperator::create(I.getOpcode(), NewRem, + Constant::getNullValue(UTy)); + } + break; + case Instruction::Add: // Replace ((add A, B) != C) with (A != C-B) if B & C are constants. if (ConstantInt *BOp1C = dyn_cast<ConstantInt>(BO->getOperand(1))) { |