From 905f311d051496023e31fa8ba98db4f5b8f54c17 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 3 May 2002 20:09:52 +0000 Subject: [PATCH] Fix bug: test/Regression/Transforms/SCCP/2002-05-03-NotOperator.ll by using the ~ operator instead of ! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2458 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 2f1fe5f8025..8edcb42530f 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -225,6 +225,8 @@ struct PointerRules : public TemplateRules { inline static ConstantPointer *CastToPointer(const ConstantPointer *V, const PointerType *PTy) { + if (V->getType() == PTy) + return const_cast(V); // Allow cast %PTy %ptr to %PTy if (V->isNullValue()) return ConstantPointerNull::get(PTy); return 0; // Can't const prop other types of pointers @@ -245,10 +247,6 @@ struct DirectRules : public TemplateRules > { - inline static Constant *Not(const ConstantClass *V) { - return ConstantClass::get(*Ty, !(BuiltinType)V->getValue());; - } - inline static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) { BuiltinType Result = (BuiltinType)V1->getValue() + @@ -310,6 +308,22 @@ struct DirectRules #undef DEF_CAST }; + +//===----------------------------------------------------------------------===// +// DirectIntRules Class +//===----------------------------------------------------------------------===// +// +// DirectIntRules provides implementations of functions that are valid on +// integer types, but not all types in general. +// +template +struct DirectIntRules : public DirectRules { + inline static Constant *Not(const ConstantClass *V) { + return ConstantClass::get(*Ty, ~(BuiltinType)V->getValue());; + } +}; + + //===----------------------------------------------------------------------===// // DirectRules Subclasses //===----------------------------------------------------------------------===// @@ -330,21 +344,21 @@ Annotation *ConstRules::find(AnnotationID AID, const Annotable *TyA, void *) { case Type::BoolTyID: return new BoolRules(); case Type::PointerTyID: return new PointerRules(); case Type::SByteTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::UByteTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::ShortTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::UShortTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::IntTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::UIntTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::LongTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::ULongTyID: - return new DirectRules(); + return new DirectIntRules(); case Type::FloatTyID: return new DirectRules(); case Type::DoubleTyID: