summaryrefslogtreecommitdiffstats
path: root/llvm/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-06-21 01:15:55 +0000
committerChris Lattner <sabre@nondot.org>2009-06-21 01:15:55 +0000
commit62fdd112fc755999175be9582eab5dac6ecba088 (patch)
tree1afec39aadaefaf8545dac0a2109b557214cab6c /llvm/lib/VMCore/ConstantFold.cpp
parent7d2b0494046e62619739b5ffeca84e0bc614ead0 (diff)
downloadbcm5719-llvm-62fdd112fc755999175be9582eab5dac6ecba088.tar.gz
bcm5719-llvm-62fdd112fc755999175be9582eab5dac6ecba088.zip
implement PR4424: 0/x is always 0 for integer division.
llvm-svn: 73835
Diffstat (limited to 'llvm/lib/VMCore/ConstantFold.cpp')
-rw-r--r--llvm/lib/VMCore/ConstantFold.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp
index 6c392145a50..dc8fb39f173 100644
--- a/llvm/lib/VMCore/ConstantFold.cpp
+++ b/llvm/lib/VMCore/ConstantFold.cpp
@@ -773,6 +773,13 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
}
}
}
+
+ // 0 / x -> 0.
+ if ((Opcode == Instruction::UDiv ||
+ Opcode == Instruction::SDiv) &&
+ CI1->isZero())
+ return const_cast<Constant*>(C1);
+
} else if (const ConstantFP *CFP1 = dyn_cast<ConstantFP>(C1)) {
if (const ConstantFP *CFP2 = dyn_cast<ConstantFP>(C2)) {
APFloat C1V = CFP1->getValueAPF();
OpenPOWER on IntegriCloud