From 5a4c808cb653999a345422758417fdd90a81c94a Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 21 Jun 2009 01:56:41 +0000 Subject: Expand this test to handle more cases (remainder and shifts) of zero. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73839 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'lib/VMCore') diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index dc8fb39..3aab0cc 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -629,7 +629,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, } } - // Handle simplifications of the RHS when a constant int. + // Handle simplifications when the RHS is a constant int. if (const ConstantInt *CI2 = dyn_cast(C2)) { switch (Opcode) { case Instruction::Add: @@ -773,13 +773,20 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, } } } - - // 0 / x -> 0. - if ((Opcode == Instruction::UDiv || - Opcode == Instruction::SDiv) && - CI1->isZero()) - return const_cast(C1); - + + switch (Opcode) { + case Instruction::SDiv: + case Instruction::UDiv: + case Instruction::URem: + case Instruction::SRem: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::Shl: + if (CI1->equalsInt(0)) return const_cast(C1); + break; + default: + break; + } } else if (const ConstantFP *CFP1 = dyn_cast(C1)) { if (const ConstantFP *CFP2 = dyn_cast(C2)) { APFloat C1V = CFP1->getValueAPF(); -- cgit v1.1