summaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/PredicateSimplifier.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2007-03-18 22:58:46 +0000
committerNick Lewycky <nicholas@mxc.ca>2007-03-18 22:58:46 +0000
commit3f64b1ab1d580e17e90367ce3916061e9a11392e (patch)
treec99ff39ebd6e2a36c05ff42e656d3d33ded781fc /lib/Transforms/Scalar/PredicateSimplifier.cpp
parent318bf7963a0e34d5ce58460ac934f97e5f80f195 (diff)
downloadllvm-3f64b1ab1d580e17e90367ce3916061e9a11392e.tar.gz
llvm-3f64b1ab1d580e17e90367ce3916061e9a11392e.tar.bz2
llvm-3f64b1ab1d580e17e90367ce3916061e9a11392e.tar.xz
Clean up this code and fix subtract miscompile.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35146 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/PredicateSimplifier.cpp')
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp40
1 files changed, 22 insertions, 18 deletions
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index f6d8878265..072110642e 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -1543,13 +1543,26 @@ namespace {
// "%x = mul i32 %y, 0" then %x EQ 0
Instruction::BinaryOps Opcode = BO->getOpcode();
+ const Type *Ty = BO->getType();
+ assert(!Ty->isFPOrFPVector() && "Float in work queue!");
+
+ Constant *Zero = Constant::getNullValue(Ty);
+ Constant *AllOnes = ConstantInt::getAllOnesValue(Ty);
switch (Opcode) {
default: break;
case Instruction::Sub:
+ if (Op1 == Zero) {
+ add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
+ return;
+ }
+ break;
+ case Instruction::Or:
+ if (Op0 == AllOnes || Op1 == AllOnes) {
+ add(BO, AllOnes, ICmpInst::ICMP_EQ, NewContext);
+ return;
+ } // fall-through
case Instruction::Add:
- case Instruction::Or: {
- Constant *Zero = Constant::getNullValue(BO->getType());
if (Op0 == Zero) {
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
return;
@@ -1557,9 +1570,8 @@ namespace {
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
return;
}
- } break;
- case Instruction::And: {
- Constant *AllOnes = ConstantInt::getAllOnesValue(BO->getType());
+ break;
+ case Instruction::And:
if (Op0 == AllOnes) {
add(BO, Op1, ICmpInst::ICMP_EQ, NewContext);
return;
@@ -1567,17 +1579,13 @@ namespace {
add(BO, Op0, ICmpInst::ICMP_EQ, NewContext);
return;
}
- } break;
- case Instruction::Mul: {
- Constant *Zero = Constant::getNullValue(BO->getType());
- if (Op0 == Zero) {
- add(BO, Zero, ICmpInst::ICMP_EQ, NewContext);
- return;
- } else if (Op1 == Zero) {
+ // fall-through
+ case Instruction::Mul:
+ if (Op0 == Zero || Op1 == Zero) {
add(BO, Zero, ICmpInst::ICMP_EQ, NewContext);
return;
}
- } break;
+ break;
}
// "%x = add i32 %y, %z" and %x EQ %y then %z EQ 0
@@ -1585,9 +1593,6 @@ namespace {
// 1. Repeat all of the above, with order of operands reversed.
// "%x = udiv i32 %y, %z" and %x EQ %y then %z EQ 1
- const Type *Ty = BO->getType();
- assert(!Ty->isFPOrFPVector() && "Float in work queue!");
-
Value *Known = Op0, *Unknown = Op1;
if (Known != BO) std::swap(Known, Unknown);
if (Known == BO) {
@@ -1596,8 +1601,7 @@ namespace {
case Instruction::Xor:
case Instruction::Add:
case Instruction::Sub:
- add(Unknown, Constant::getNullValue(Ty), ICmpInst::ICMP_EQ,
- NewContext);
+ add(Unknown, Zero, ICmpInst::ICMP_EQ, NewContext);
break;
case Instruction::UDiv:
case Instruction::SDiv: