aboutsummaryrefslogtreecommitdiff
path: root/lib/VMCore/ConstantFold.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-11-17 20:19:35 +0000
committerChris Lattner <sabre@nondot.org>2003-11-17 20:19:35 +0000
commit5d5a714b24f1e31ca98f697dc02ff9b554e258cc (patch)
treed4d0055da84b1fb10ef6e549bf67298bac6fe770 /lib/VMCore/ConstantFold.h
parent48babfa60d3ee1854f33ad93e07abb2b22cf8ab8 (diff)
Implement == and != correctly. Before they would incorrectly return !=
for some constant exprs when they could really be the same value git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/ConstantFold.h')
-rw-r--r--lib/VMCore/ConstantFold.h25
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/VMCore/ConstantFold.h b/lib/VMCore/ConstantFold.h
index d733ac8096..27eed8a7be 100644
--- a/lib/VMCore/ConstantFold.h
+++ b/lib/VMCore/ConstantFold.h
@@ -48,19 +48,6 @@ namespace llvm {
class PointerType;
//===----------------------------------------------------------------------===//
-// Implement == and != directly...
-//===----------------------------------------------------------------------===//
-
-inline ConstantBool *operator==(const Constant &V1, const Constant &V2) {
- assert(V1.getType() == V2.getType() && "Constant types must be identical!");
- return ConstantBool::get(&V1 == &V2);
-}
-
-inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
- return ConstantBool::get(&V1 != &V2);
-}
-
-//===----------------------------------------------------------------------===//
// Implement all other operators indirectly through TypeRules system
//===----------------------------------------------------------------------===//
@@ -81,6 +68,8 @@ struct ConstRules {
virtual ConstantBool *lessthan(const Constant *V1,
const Constant *V2) const = 0;
+ virtual ConstantBool *equalto(const Constant *V1,
+ const Constant *V2) const = 0;
// Casting operators. ick
virtual ConstantBool *castToBool (const Constant *V) const = 0;
@@ -195,11 +184,21 @@ inline ConstantBool *operator<(const Constant &V1,
return ConstRules::get(V1, V2).lessthan(&V1, &V2);
}
+inline ConstantBool *operator==(const Constant &V1, const Constant &V2) {
+ assert(V1.getType() == V2.getType() && "Constant types must be identical!");
+ return ConstRules::get(V1, V2).equalto(&V1, &V2);
+}
//===----------------------------------------------------------------------===//
// Implement 'derived' operators based on what we already have...
//===----------------------------------------------------------------------===//
+inline ConstantBool *operator!=(const Constant &V1, const Constant &V2) {
+ if (ConstantBool *V = (V1 == V2))
+ return V->inverted(); // !(V1 == V2)
+ return 0;
+}
+
inline ConstantBool *operator>(const Constant &V1,
const Constant &V2) {
return V2 < V1;