diff options
author | Nick Lewycky <nicholas@mxc.ca> | 2009-06-21 01:56:41 +0000 |
---|---|---|
committer | Nick Lewycky <nicholas@mxc.ca> | 2009-06-21 01:56:41 +0000 |
commit | 6b8320fa5b16b748e7119cad9f5ef2e95a11e376 (patch) | |
tree | f6dce192aee4f5c6148f64c52e27bba7c4fa460f /llvm/lib/VMCore/ConstantFold.cpp | |
parent | 98b13ac6f3f56af0a51c8015a2b695e70e41a522 (diff) | |
download | bcm5719-llvm-6b8320fa5b16b748e7119cad9f5ef2e95a11e376.tar.gz bcm5719-llvm-6b8320fa5b16b748e7119cad9f5ef2e95a11e376.zip |
Expand this test to handle more cases (remainder and shifts) of zero.
llvm-svn: 73839
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index dc8fb39f173..3aab0cce37e 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/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<ConstantInt>(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<Constant*>(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<Constant*>(C1); + break; + default: + break; + } } else if (const ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) { if (const ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) { APFloat C1V = CFP1->getValueAPF(); |