summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/SCCP.cpp
diff options
context:
space:
mode:
authorDavide Italiano <davide@freebsd.org>2017-01-19 23:07:51 +0000
committerDavide Italiano <davide@freebsd.org>2017-01-19 23:07:51 +0000
commit6c2c3e07bfaa1a021bf665971b018491a728a895 (patch)
tree40dbd17044c80ff0fdcb0c63479680733eb7b46a /llvm/lib/Transforms/Scalar/SCCP.cpp
parent5a52af0f63af33ceca08ac39f04738f37bd746ea (diff)
downloadbcm5719-llvm-6c2c3e07bfaa1a021bf665971b018491a728a895.tar.gz
bcm5719-llvm-6c2c3e07bfaa1a021bf665971b018491a728a895.zip
[SCCP] Teach the pass how to handle `div` with overdefined operands.
This can prove that: extern int f; int g() { int x = 0; for (int i = 0; i < 365; ++i) { x /= f; } return x; } always returns zero. Thanks to Sanjoy for confirming this transformation actually made sense (bugs are mine). llvm-svn: 292531
Diffstat (limited to 'llvm/lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index 9c5fa5c1426..334642fe35d 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -910,6 +910,12 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
// Otherwise, one of our operands is overdefined. Try to produce something
// better than overdefined with some tricks.
+ // If this is 0 / Y, it doesn't matter that the second operand is
+ // overdefined, and we can replace it with zero.
+ if (I.getOpcode() == Instruction::UDiv || I.getOpcode() == Instruction::SDiv)
+ if (V1State.isConstant() && V1State.getConstant()->isNullValue())
+ return markConstant(IV, &I, V1State.getConstant());
+
// If this is:
// -> AND/MUL with 0
// -> OR with -1
OpenPOWER on IntegriCloud