From 3571b726068de0a1d40acd4552cf2d03cc899254 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 6 Jul 2004 07:38:18 +0000 Subject: [PATCH] Implement rem.ll:test3 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14640 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index be1111fbd53..4f6724ff52f 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/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(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(BO->getOperand(1)) && + BO->hasOneUse() && + cast(BO->getOperand(1))->getValue() > 1) + if (unsigned L2 = + Log2(cast(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(BO->getOperand(1))) {