aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.cpp
diff options
context:
space:
mode:
authorNick Lewycky <nicholas@mxc.ca>2009-09-20 00:04:02 +0000
committerNick Lewycky <nicholas@mxc.ca>2009-09-20 00:04:02 +0000
commitf4d18827430be9ac3a7a5216be61224146d97f44 (patch)
tree5eec82fe4292e5562801d58be0180c714fd1afe6 /lib/VMCore/ConstantFold.cpp
parent970e7dff5ba2bd8c5613c43e3b215ca940a378e9 (diff)
Teach the constant folder how to handle a few simple i1 cases.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.cpp')
-rw-r--r--lib/VMCore/ConstantFold.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index 15b6df90a4..f2b8ad5d92 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -1010,6 +1010,37 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
}
}
+ // i1 can be simplified in many cases.
+ if (C1->getType() == Type::getInt1Ty(Context)) {
+ switch (Opcode) {
+ case Instruction::Add:
+ case Instruction::Sub:
+ return ConstantExpr::getXor(const_cast<Constant*>(C1),
+ const_cast<Constant*>(C2));
+ case Instruction::Mul:
+ return ConstantExpr::getAnd(const_cast<Constant*>(C1),
+ const_cast<Constant*>(C2));
+ case Instruction::Shl:
+ case Instruction::LShr:
+ case Instruction::AShr:
+ // We can assume that C2 == 0. If it were one the result would be
+ // undefined because the shift value is as large as the bitwidth.
+ return const_cast<Constant*>(C1);
+ case Instruction::SDiv:
+ case Instruction::UDiv:
+ // We can assume that C2 == 1. If it were zero the result would be
+ // undefined through division by zero.
+ return const_cast<Constant*>(C1);
+ case Instruction::URem:
+ case Instruction::SRem:
+ // We can assume that C2 == 1. If it were zero the result would be
+ // undefined through division by zero.
+ return ConstantInt::getFalse(Context);
+ default:
+ break;
+ }
+ }
+
// We don't know how to fold this.
return 0;
}