aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/iOperators.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-09-01 19:46:40 +0000
committerChris Lattner <sabre@nondot.org>2002-09-01 19:46:40 +0000
commitea8b7b8bb50eb56015973426890d9ec6ab9ed4f1 (patch)
treeafa3c7e3187b24baad8b71f34f5f8c15479e35c2 /lib/VMCore/iOperators.cpp
parent3d92ac255eda41845ce08bc5f0d2676a55965ede (diff)
downloadexternal_llvm-ea8b7b8bb50eb56015973426890d9ec6ab9ed4f1.zip
external_llvm-ea8b7b8bb50eb56015973426890d9ec6ab9ed4f1.tar.gz
external_llvm-ea8b7b8bb50eb56015973426890d9ec6ab9ed4f1.tar.bz2
- Exposed SetCondInst::getInverseCondition & ::getSwappedCondition better
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3562 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/iOperators.cpp')
-rw-r--r--lib/VMCore/iOperators.cpp32
1 files changed, 23 insertions, 9 deletions
diff --git a/lib/VMCore/iOperators.cpp b/lib/VMCore/iOperators.cpp
index ba5aca1..c7d757e 100644
--- a/lib/VMCore/iOperators.cpp
+++ b/lib/VMCore/iOperators.cpp
@@ -87,18 +87,17 @@ const Value *BinaryOperator::getNotArgument(const BinaryOperator *Bop) {
// order dependant (SetLT f.e.) the opcode is changed.
//
bool BinaryOperator::swapOperands() {
+ if (SetCondInst *SCI = dyn_cast<SetCondInst>(this)) {
+ iType = SCI->getSwappedCondition();
+ std::swap(Operands[0], Operands[1]);
+ return false;
+ }
+
switch (getOpcode()) {
// Instructions that don't need opcode modification
case Add: case Mul:
case And: case Xor:
case Or:
- case SetEQ: case SetNE:
- break;
- // Instructions that need opcode modification
- case SetGT: iType = SetLT; break;
- case SetLT: iType = SetGT; break;
- case SetGE: iType = SetLE; break;
- case SetLE: iType = SetGE; break;
// Error on the side of caution
default:
return true;
@@ -126,8 +125,8 @@ SetCondInst::SetCondInst(BinaryOps opType, Value *S1, Value *S2,
// getInverseCondition - Return the inverse of the current condition opcode.
// For example seteq -> setne, setgt -> setle, setlt -> setge, etc...
//
-Instruction::BinaryOps SetCondInst::getInverseCondition() const {
- switch (getOpcode()) {
+Instruction::BinaryOps SetCondInst::getInverseCondition(BinaryOps Opcode) {
+ switch (Opcode) {
default:
assert(0 && "Unknown setcc opcode!");
case SetEQ: return SetNE;
@@ -138,3 +137,18 @@ Instruction::BinaryOps SetCondInst::getInverseCondition() const {
case SetLE: return SetGT;
}
}
+
+// getSwappedCondition - Return the condition opcode that would be the result
+// of exchanging the two operands of the setcc instruction without changing
+// the result produced. Thus, seteq->seteq, setle->setge, setlt->setgt, etc.
+//
+Instruction::BinaryOps SetCondInst::getSwappedCondition(BinaryOps Opcode) {
+ switch (Opcode) {
+ default: assert(0 && "Unknown setcc instruction!");
+ case SetEQ: case SetNE: return Opcode;
+ case SetGT: return SetLT;
+ case SetLT: return SetGT;
+ case SetGE: return SetLE;
+ case SetLE: return SetGE;
+ }
+}