[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2007-02-23 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.137 - 1.138
---
Log message:

Fix Transforms/ConstProp/2007-02-23-sdiv.ll and PR1215: http://llvm.org/PR1215 


---
Diffs of the changes:  (+2 -1)

 ConstantFolding.cpp |3 ++-
 1 files changed, 2 insertions(+), 1 deletion(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.137 
llvm/lib/VMCore/ConstantFolding.cpp:1.138
--- llvm/lib/VMCore/ConstantFolding.cpp:1.137   Wed Feb 14 21:39:18 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Feb 23 19:19:50 2007
@@ -574,7 +574,8 @@
 if (CI2-isAllOnesValue() 
 (((CI1-getType()-getPrimitiveSizeInBits() == 64)  
   (CI1-getSExtValue() == INT64_MIN)) ||
- (CI1-getSExtValue() == -CI1-getSExtValue(
+ (CI1-getSExtValue() == -CI1-getSExtValue() 
+  CI1-getSExtValue(
   return 0;  // MIN_INT / -1 - overflow
 return ConstantInt::get(C1-getType(), 
 CI1-getSExtValue() / CI2-getSExtValue());



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Instructions.cpp Type.cpp Verifier.cpp

2007-02-14 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.136 - 1.137
Constants.cpp updated: 1.210 - 1.211
Instructions.cpp updated: 1.76 - 1.77
Type.cpp updated: 1.173 - 1.174
Verifier.cpp updated: 1.196 - 1.197
---
Log message:

For PR1195: http://llvm.org/PR1195 :
Change use of packed term to vector in comments, strings, variable
names, etc.


---
Diffs of the changes:  (+10 -10)

 ConstantFolding.cpp |2 +-
 Constants.cpp   |   12 ++--
 Instructions.cpp|2 +-
 Type.cpp|2 +-
 Verifier.cpp|2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.136 
llvm/lib/VMCore/ConstantFolding.cpp:1.137
--- llvm/lib/VMCore/ConstantFolding.cpp:1.136   Wed Feb 14 20:26:10 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Feb 14 21:39:18 2007
@@ -36,7 +36,7 @@
 
//===--===//
 
 /// CastConstantVector - Convert the specified ConstantVector node to the
-/// specified packed type.  At this point, we know that the elements of the
+/// specified vector type.  At this point, we know that the elements of the
 /// input packed constant are all simple integer or FP values.
 static Constant *CastConstantVector(ConstantVector *CP,
 const VectorType *DstTy) {


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.210 llvm/lib/VMCore/Constants.cpp:1.211
--- llvm/lib/VMCore/Constants.cpp:1.210 Wed Feb 14 20:26:10 2007
+++ llvm/lib/VMCore/Constants.cpp   Wed Feb 14 21:39:18 2007
@@ -1135,7 +1135,7 @@
 }
 
 static ManagedStaticValueMapstd::vectorConstant*, VectorType,
-  ConstantVector  PackedConstants;
+  ConstantVector  VectorConstants;
 
 Constant *ConstantVector::get(const VectorType *Ty,
   const std::vectorConstant* V) {
@@ -1143,10 +1143,10 @@
   if (!V.empty()) {
 Constant *C = V[0];
 if (!C-isNullValue())
-  return PackedConstants-getOrCreate(Ty, V);
+  return VectorConstants-getOrCreate(Ty, V);
 for (unsigned i = 1, e = V.size(); i != e; ++i)
   if (V[i] != C)
-return PackedConstants-getOrCreate(Ty, V);
+return VectorConstants-getOrCreate(Ty, V);
   }
   return ConstantAggregateZero::get(Ty);
 }
@@ -1159,7 +1159,7 @@
 // destroyConstant - Remove the constant from the constant table...
 //
 void ConstantVector::destroyConstant() {
-  PackedConstants-remove(this);
+  VectorConstants-remove(this);
   destroyConstantImpl();
 }
 
@@ -1793,7 +1793,7 @@
 
 Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) {
   assert(isaVectorType(Val-getType()) 
- Tried to create extractelement operation on non-packed type!);
+ Tried to create extractelement operation on non-vector type!);
   assert(Idx-getType() == Type::Int32Ty 
  Extractelement index must be i32 type!);
   return 
getExtractElementTy(castVectorType(Val-getType())-getElementType(),
@@ -1815,7 +1815,7 @@
 Constant *ConstantExpr::getInsertElement(Constant *Val, Constant *Elt, 
  Constant *Idx) {
   assert(isaVectorType(Val-getType()) 
- Tried to create insertelement operation on non-packed type!);
+ Tried to create insertelement operation on non-vector type!);
   assert(Elt-getType() == castVectorType(Val-getType())-getElementType()
   Insertelement types must match!);
   assert(Idx-getType() == Type::Int32Ty 


Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.76 
llvm/lib/VMCore/Instructions.cpp:1.77
--- llvm/lib/VMCore/Instructions.cpp:1.76   Wed Feb 14 20:26:10 2007
+++ llvm/lib/VMCore/Instructions.cppWed Feb 14 21:39:18 2007
@@ -1000,7 +1000,7 @@
 bool InsertElementInst::isValidOperands(const Value *Vec, const Value *Elt, 
 const Value *Index) {
   if (!isaVectorType(Vec-getType()))
-return false;   // First operand of insertelement must be packed type.
+return false;   // First operand of insertelement must be vector type.
   
   if (Elt-getType() != castVectorType(Vec-getType())-getElementType())
 return false;// Second operand of insertelement must be packed element 
type.


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.173 llvm/lib/VMCore/Type.cpp:1.174
--- llvm/lib/VMCore/Type.cpp:1.173  Wed Feb 14 21:11:50 2007
+++ llvm/lib/VMCore/Type.cppWed Feb 14 21:39:18 2007
@@ -110,7 +110,7 @@
   if (!this-isFirstClassType() || !Ty-isFirstClassType())
 return false;
 
-  // Packed - Packed conversions are always lossless if the two packed types
+  // Vector - Vector conversions are always lossless if the two vector types
   // have the same size, otherwise not.
   if (const VectorType *thisPTy = dyn_castVectorType(this))
 if (const VectorType 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp ConstantFolding.h Constants.cpp Instructions.cpp

2007-01-30 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.133 - 1.134
ConstantFolding.h updated: 1.52 - 1.53
Constants.cpp updated: 1.205 - 1.206
Instructions.cpp updated: 1.66 - 1.67
---
Log message:

Revise APIs for creating constantexpr GEPs to not require the use of vectors.  
This allows us to eliminate many temporary vectors, and theirassociated 
malloc/free pairs.



---
Diffs of the changes:  (+47 -46)

 ConstantFolding.cpp |   37 +
 ConstantFolding.h   |4 +---
 Constants.cpp   |   41 +++--
 Instructions.cpp|   11 ++-
 4 files changed, 47 insertions(+), 46 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.133 
llvm/lib/VMCore/ConstantFolding.cpp:1.134
--- llvm/lib/VMCore/ConstantFolding.cpp:1.133   Fri Jan 19 15:13:56 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Jan 30 22:40:28 2007
@@ -23,6 +23,7 @@
 #include llvm/Instructions.h
 #include llvm/DerivedTypes.h
 #include llvm/Function.h
+#include llvm/ADT/SmallVector.h
 #include llvm/Support/Compiler.h
 #include llvm/Support/GetElementPtrTypeIterator.h
 #include llvm/Support/ManagedStatic.h
@@ -216,7 +217,7 @@
 // the first element.  If so, return the appropriate GEP instruction.
 if (const PointerType *PTy = dyn_castPointerType(V-getType()))
   if (const PointerType *DPTy = dyn_castPointerType(DestTy)) {
-std::vectorValue* IdxList;
+SmallVectorValue*, 8 IdxList;
 IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
 const Type *ElTy = PTy-getElementType();
 while (ElTy != DPTy-getElementType()) {
@@ -236,7 +237,7 @@
 
 if (ElTy == DPTy-getElementType())
   return ConstantExpr::getGetElementPtr(
-  const_castConstant*(V),IdxList);
+  const_castConstant*(V), IdxList[0], IdxList.size());
   }
 
 // Handle casts from one packed constant to another.  We know that the src 
@@ -1290,28 +1291,31 @@
 }
 
 Constant *llvm::ConstantFoldGetElementPtr(const Constant *C,
-  const std::vectorValue* IdxList) {
-  if (IdxList.size() == 0 ||
-  (IdxList.size() == 1  castConstant(IdxList[0])-isNullValue()))
+  Constant* const *Idxs, 
+  unsigned NumIdx) {
+  if (NumIdx == 0 ||
+  (NumIdx == 1  Idxs[0]-isNullValue()))
 return const_castConstant*(C);
 
   if (isaUndefValue(C)) {
-const Type *Ty = GetElementPtrInst::getIndexedType(C-getType(), IdxList,
+const Type *Ty = GetElementPtrInst::getIndexedType(C-getType(),
+   (Value**)Idxs, NumIdx,
true);
 assert(Ty != 0  Invalid indices for GEP!);
 return UndefValue::get(PointerType::get(Ty));
   }
 
-  Constant *Idx0 = castConstant(IdxList[0]);
+  Constant *Idx0 = Idxs[0];
   if (C-isNullValue()) {
 bool isNull = true;
-for (unsigned i = 0, e = IdxList.size(); i != e; ++i)
-  if (!castConstant(IdxList[i])-isNullValue()) {
+for (unsigned i = 0, e = NumIdx; i != e; ++i)
+  if (!Idxs[i]-isNullValue()) {
 isNull = false;
 break;
   }
 if (isNull) {
-  const Type *Ty = GetElementPtrInst::getIndexedType(C-getType(), IdxList,
+  const Type *Ty = GetElementPtrInst::getIndexedType(C-getType(),
+ (Value**)Idxs, NumIdx,
  true);
   assert(Ty != 0  Invalid indices for GEP!);
   return ConstantPointerNull::get(PointerType::get(Ty));
@@ -1330,8 +1334,8 @@
 LastTy = *I;
 
   if ((LastTy  isaArrayType(LastTy)) || Idx0-isNullValue()) {
-std::vectorValue* NewIndices;
-NewIndices.reserve(IdxList.size() + CE-getNumOperands());
+SmallVectorValue*, 16 NewIndices;
+NewIndices.reserve(NumIdx + CE-getNumOperands());
 for (unsigned i = 1, e = CE-getNumOperands()-1; i != e; ++i)
   NewIndices.push_back(CE-getOperand(i));
 
@@ -1353,8 +1357,9 @@
 }
 
 NewIndices.push_back(Combined);
-NewIndices.insert(NewIndices.end(), IdxList.begin()+1, IdxList.end());
-return ConstantExpr::getGetElementPtr(CE-getOperand(0), NewIndices);
+NewIndices.insert(NewIndices.end(), Idxs+1, Idxs+NumIdx);
+return ConstantExpr::getGetElementPtr(CE-getOperand(0), 
NewIndices[0],
+  NewIndices.size());
   }
 }
 
@@ -1363,7 +1368,7 @@
 //long 0, long 0)
 // To: int* getelementptr ([3 x int]* %X, long 0, long 0)
 //
-if (CE-isCast()  IdxList.size()  1  Idx0-isNullValue())
+if (CE-isCast()  NumIdx  1  Idx0-isNullValue())
   if (const PointerType *SPT =
   

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Type.cpp ValueTypes.cpp

2007-01-19 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.132 - 1.133
Constants.cpp updated: 1.201 - 1.202
Type.cpp updated: 1.163 - 1.164
ValueTypes.cpp updated: 1.10 - 1.11
---
Log message:

For PR1043: http://llvm.org/PR1043 :
This is the final patch for this PR. It implements some minor cleanup 
in the use of IntegerType, to wit:
1. Type::getIntegerTypeMask - IntegerType::getBitMask
2. Type::Int*Ty changed to IntegerType* from Type*
3. ConstantInt::getType() returns IntegerType* now, not Type*

This also fixes PR1120: http://llvm.org/PR1120 .

Patch by Sheng Zhou.



---
Diffs of the changes:  (+14 -9)

 ConstantFolding.cpp |7 +--
 Constants.cpp   |4 ++--
 Type.cpp|   11 ++-
 ValueTypes.cpp  |1 +
 4 files changed, 14 insertions(+), 9 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.132 
llvm/lib/VMCore/ConstantFolding.cpp:1.133
--- llvm/lib/VMCore/ConstantFolding.cpp:1.132   Sun Jan 14 20:27:26 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Jan 19 15:13:56 2007
@@ -295,13 +295,8 @@
 // Handle ConstantFP input.
 if (const ConstantFP *FP = dyn_castConstantFP(V)) {
   // FP - Integral.
-  if (DestTy-isInteger()) {
-if (DestTy == Type::Int32Ty)
-  return ConstantInt::get(DestTy, FloatToBits(FP-getValue()));
-assert(DestTy == Type::Int64Ty  
-   Incorrect integer type for bitcast!);
+  if (DestTy-isInteger())
 return ConstantInt::get(DestTy, DoubleToBits(FP-getValue()));
-  }
 }
 return 0;
   default:


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.201 llvm/lib/VMCore/Constants.cpp:1.202
--- llvm/lib/VMCore/Constants.cpp:1.201 Sun Jan 14 20:27:26 2007
+++ llvm/lib/VMCore/Constants.cpp   Fri Jan 19 15:13:56 2007
@@ -568,7 +568,7 @@
   unsigned NumBits = castIntegerType(Ty)-getBitWidth(); // assert okay
   assert(NumBits = 64  Not implemented: integers  64-bits);
   if (Ty == Type::Int1Ty)
-return Val == 0 || Val == 1;
+return Val == 0 || Val == 1 || Val == -1;
   if (NumBits == 64)
 return true; // always true, has to fit in largest type
   int64_t Min = -(1ll  (NumBits-1));
@@ -849,7 +849,7 @@
   return getTrue();
 else
   return getFalse();
-  return IntConstants-getOrCreate(Ty, V  Ty-getIntegerTypeMask());
+  return IntConstants-getOrCreate(Ty, V  
castIntegerType(Ty)-getBitMask());
 }
 
 // ConstantFP::get() implementation...


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.163 llvm/lib/VMCore/Type.cpp:1.164
--- llvm/lib/VMCore/Type.cpp:1.163  Thu Jan 18 12:14:49 2007
+++ llvm/lib/VMCore/Type.cppFri Jan 19 15:13:56 2007
@@ -81,6 +81,15 @@
   }
 }
 
+const Type *Type::getVAArgsPromotedType() const {
+  if (ID == IntegerTyID  getSubclassData()  32)
+return Type::Int32Ty;
+  else if (ID == FloatTyID)
+return Type::DoubleTy;
+  else
+return this;
+}
+
 /// isFPOrFPVector - Return true if this is a FP type or a vector of FP types.
 ///
 bool Type::isFPOrFPVector() const {
@@ -352,7 +361,7 @@
 };   \
   }  \
   static ManagedStaticTY##Type The##TY##Ty;\
-  const Type *Type::TY##Ty = *The##TY##Ty
+  const IntegerType *Type::TY##Ty = *The##TY##Ty
 
 DeclarePrimType(Void,   void);
 DeclarePrimType(Float,  float);


Index: llvm/lib/VMCore/ValueTypes.cpp
diff -u llvm/lib/VMCore/ValueTypes.cpp:1.10 llvm/lib/VMCore/ValueTypes.cpp:1.11
--- llvm/lib/VMCore/ValueTypes.cpp:1.10 Thu Jan 11 12:21:29 2007
+++ llvm/lib/VMCore/ValueTypes.cpp  Fri Jan 19 15:13:56 2007
@@ -13,6 +13,7 @@
 
 #include llvm/CodeGen/ValueTypes.h
 #include llvm/Type.h
+#include llvm/DerivedTypes.h
 using namespace llvm;
 
 /// MVT::getValueTypeString - This function returns value type as a string,



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2007-01-12 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.130 - 1.131
---
Log message:

Remove a bunch of duplicated code.  Among other things, this fixes 
constant folding of signed comparisons of bool.


---
Diffs of the changes:  (+50 -93)

 ConstantFolding.cpp |  143 ++--
 1 files changed, 50 insertions(+), 93 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.130 
llvm/lib/VMCore/ConstantFolding.cpp:1.131
--- llvm/lib/VMCore/ConstantFolding.cpp:1.130   Fri Jan 12 01:05:14 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Jan 12 12:42:52 2007
@@ -554,71 +554,55 @@
   // so look at directly computing the value.
   if (const ConstantInt *CI1 = dyn_castConstantInt(C1)) {
 if (const ConstantInt *CI2 = dyn_castConstantInt(C2)) {
-  if (CI1-getType() == Type::Int1Ty  CI2-getType() == Type::Int1Ty) {
-switch (Opcode) {
-  default:
-break;
-  case Instruction::And:
-return ConstantInt::get(Type::Int1Ty, 
-CI1-getZExtValue()  CI2-getZExtValue());
-  case Instruction::Or:
-return ConstantInt::get(Type::Int1Ty, 
-CI1-getZExtValue() | CI2-getZExtValue());
-  case Instruction::Xor:
-return ConstantInt::get(Type::Int1Ty, 
-CI1-getZExtValue() ^ CI2-getZExtValue());
-}
-  } else {
-uint64_t C1Val = CI1-getZExtValue();
-uint64_t C2Val = CI2-getZExtValue();
-switch (Opcode) {
-default:
-  break;
-case Instruction::Add: 
-  return ConstantInt::get(C1-getType(), C1Val + C2Val);
-case Instruction::Sub: 
-  return ConstantInt::get(C1-getType(), C1Val - C2Val);
-case Instruction::Mul: 
-  return ConstantInt::get(C1-getType(), C1Val * C2Val);
-case Instruction::UDiv:
-  if (CI2-isNullValue())  // X / 0 - can't fold
-return 0;
-  return ConstantInt::get(C1-getType(), C1Val / C2Val);
-case Instruction::SDiv:
-  if (CI2-isNullValue()) return 0;// X / 0 - can't fold
-  if (CI2-isAllOnesValue() 
-  (((CI1-getType()-getPrimitiveSizeInBits() == 64)  
-(CI1-getSExtValue() == INT64_MIN)) ||
-   (CI1-getSExtValue() == -CI1-getSExtValue(
-return 0;  // MIN_INT / -1 - overflow
-  return ConstantInt::get(C1-getType(), 
-  CI1-getSExtValue() / CI2-getSExtValue());
-case Instruction::URem:
-  if (C2-isNullValue()) return 0; // X / 0 - can't fold
-  return ConstantInt::get(C1-getType(), C1Val % C2Val);
-case Instruction::SRem:
-  if (CI2-isNullValue()) return 0;// X % 0 - can't fold
-  if (CI2-isAllOnesValue()   
-  (((CI1-getType()-getPrimitiveSizeInBits() == 64)  
-(CI1-getSExtValue() == INT64_MIN)) ||
-   (CI1-getSExtValue() == -CI1-getSExtValue(
-return 0;  // MIN_INT % -1 - overflow
-  return ConstantInt::get(C1-getType(), 
-  CI1-getSExtValue() % CI2-getSExtValue());
-case Instruction::And:
-  return ConstantInt::get(C1-getType(), C1Val  C2Val);
-case Instruction::Or:
-  return ConstantInt::get(C1-getType(), C1Val | C2Val);
-case Instruction::Xor:
-  return ConstantInt::get(C1-getType(), C1Val ^ C2Val);
-case Instruction::Shl:
-  return ConstantInt::get(C1-getType(), C1Val  C2Val);
-case Instruction::LShr:
-  return ConstantInt::get(C1-getType(), C1Val  C2Val);
-case Instruction::AShr:
-  return ConstantInt::get(C1-getType(), 
-  CI1-getSExtValue()  C2Val);
-}
+  uint64_t C1Val = CI1-getZExtValue();
+  uint64_t C2Val = CI2-getZExtValue();
+  switch (Opcode) {
+  default:
+break;
+  case Instruction::Add: 
+return ConstantInt::get(C1-getType(), C1Val + C2Val);
+  case Instruction::Sub: 
+return ConstantInt::get(C1-getType(), C1Val - C2Val);
+  case Instruction::Mul: 
+return ConstantInt::get(C1-getType(), C1Val * C2Val);
+  case Instruction::UDiv:
+if (CI2-isNullValue())  // X / 0 - can't fold
+  return 0;
+return ConstantInt::get(C1-getType(), C1Val / C2Val);
+  case Instruction::SDiv:
+if (CI2-isNullValue()) return 0;// X / 0 - can't fold
+if (CI2-isAllOnesValue() 
+(((CI1-getType()-getPrimitiveSizeInBits() == 64)  
+  (CI1-getSExtValue() == INT64_MIN)) ||
+ (CI1-getSExtValue() == 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2007-01-10 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.125 - 1.126
---
Log message:

Implement better constant folding of unordered FCMP predicates.


---
Diffs of the changes:  (+27 -7)

 ConstantFolding.cpp |   34 +++---
 1 files changed, 27 insertions(+), 7 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.125 
llvm/lib/VMCore/ConstantFolding.cpp:1.126
--- llvm/lib/VMCore/ConstantFolding.cpp:1.125   Wed Jan  3 20:13:20 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Jan 10 18:25:45 2007
@@ -1110,18 +1110,38 @@
 case FCmpInst::FCMP_FALSE: return ConstantBool::getFalse();
 case FCmpInst::FCMP_TRUE:  return ConstantBool::getTrue();
 case FCmpInst::FCMP_UNO:
-case FCmpInst::FCMP_ORD:   break; // Can't fold these
+  return ConstantBool::get(C1Val != C1Val || C2Val != C2Val);
+case FCmpInst::FCMP_ORD:
+  return ConstantBool::get(C1Val == C1Val  C2Val == C2Val);
 case FCmpInst::FCMP_UEQ:
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
 case FCmpInst::FCMP_OEQ:   return ConstantBool::get(C1Val == C2Val);
-case FCmpInst::FCMP_ONE:
-case FCmpInst::FCMP_UNE:   return ConstantBool::get(C1Val != C2Val);
-case FCmpInst::FCMP_OLT: 
-case FCmpInst::FCMP_ULT:   return ConstantBool::get(C1Val  C2Val);
+case FCmpInst::FCMP_UNE:
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
+case FCmpInst::FCMP_ONE:   return ConstantBool::get(C1Val != C2Val);
+case FCmpInst::FCMP_ULT: 
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
+case FCmpInst::FCMP_OLT:   return ConstantBool::get(C1Val  C2Val);
 case FCmpInst::FCMP_UGT:
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
 case FCmpInst::FCMP_OGT:   return ConstantBool::get(C1Val  C2Val);
-case FCmpInst::FCMP_OLE:
-case FCmpInst::FCMP_ULE:   return ConstantBool::get(C1Val = C2Val);
+case FCmpInst::FCMP_ULE:
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
+case FCmpInst::FCMP_OLE:   return ConstantBool::get(C1Val = C2Val);
 case FCmpInst::FCMP_UGE:
+  if (C1Val != C1Val || C2Val != C2Val)
+return ConstantBool::getTrue();
+  /* FALL THROUGH */
 case FCmpInst::FCMP_OGE:   return ConstantBool::get(C1Val = C2Val);
 }
   } else if (const ConstantPacked *CP1 = dyn_castConstantPacked(C1)) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2007-01-03 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.123 - 1.124
---
Log message:

fix some bugs handling vectors, avoid host-specific handling of undefined shift 
results.


---
Diffs of the changes:  (+15 -5)

 ConstantFolding.cpp |   20 +++-
 1 files changed, 15 insertions(+), 5 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.123 
llvm/lib/VMCore/ConstantFolding.cpp:1.124
--- llvm/lib/VMCore/ConstantFolding.cpp:1.123   Sun Dec 31 15:43:30 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Jan  3 19:56:39 2007
@@ -444,6 +444,8 @@
 return Constant::getNullValue(C1-getType());
   return const_castConstant*(C2);// X / undef - undef
 case Instruction::Or:  // X | undef - -1
+  if (const PackedType *PTy = dyn_castPackedType(C1-getType()))
+return ConstantPacked::getAllOnesValue(PTy);
   return ConstantInt::getAllOnesValue(C1-getType());
 case Instruction::LShr:
   if (isaUndefValue(C2)  isaUndefValue(C1))
@@ -496,8 +498,9 @@
 return Constant::getNullValue(CI-getType()); // X % 1 == 0
 break;
   case Instruction::And:
-if (castConstantIntegral(C2)-isAllOnesValue())
-  return const_castConstant*(C1);   // X  -1 == 
X
+if (const ConstantInt *CI = dyn_castConstantInt(C2))
+  if (CI-isAllOnesValue())
+return const_castConstant*(C1); // X  -1 == 
X
 if (C2-isNullValue()) return const_castConstant*(C2);  // X  0 == 0
 if (CE1-isCast()  isaGlobalValue(CE1-getOperand(0))) {
   GlobalValue *CPR = castGlobalValue(CE1-getOperand(0));
@@ -511,8 +514,9 @@
 break;
   case Instruction::Or:
 if (C2-isNullValue()) return const_castConstant*(C1);  // X | 0 == X
-if (castConstantIntegral(C2)-isAllOnesValue())
-  return const_castConstant*(C2);  // X | -1 == -1
+if (const ConstantInt *CI = dyn_castConstantInt(C2))
+  if (CI-isAllOnesValue())
+return const_castConstant*(C2);  // X | -1 == -1
 break;
   case Instruction::Xor:
 if (C2-isNullValue()) return const_castConstant*(C1);  // X ^ 0 == X
@@ -547,7 +551,7 @@
   }
 
   // At this point we know neither constant is an UndefValue nor a ConstantExpr
-  // so look at directly computing the 
+  // so look at directly computing the value.
   if (const ConstantBool *CB1 = dyn_castConstantBool(C1)) {
 if (const ConstantBool *CB2 = dyn_castConstantBool(C2)) {
   switch (Opcode) {
@@ -606,10 +610,16 @@
   case Instruction::Xor:
 return ConstantInt::get(C1-getType(), C1Val ^ C2Val);
   case Instruction::Shl:
+if (C2Val = CI1-getType()-getPrimitiveSizeInBits())
+  C2Val = CI1-getType()-getPrimitiveSizeInBits() - 1;
 return ConstantInt::get(C1-getType(), C1Val  C2Val);
   case Instruction::LShr:
+if (C2Val = CI1-getType()-getPrimitiveSizeInBits())
+  C2Val = CI1-getType()-getPrimitiveSizeInBits() - 1;
 return ConstantInt::get(C1-getType(), C1Val  C2Val);
   case Instruction::AShr:
+if (C2Val = CI1-getType()-getPrimitiveSizeInBits())
+  C2Val = CI1-getType()-getPrimitiveSizeInBits() - 1;
 return ConstantInt::get(C1-getType(), 
 CI1-getSExtValue()  C2Val);
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2007-01-03 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.124 - 1.125
---
Log message:

fix typo


---
Diffs of the changes:  (+1 -1)

 ConstantFolding.cpp |2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.124 
llvm/lib/VMCore/ConstantFolding.cpp:1.125
--- llvm/lib/VMCore/ConstantFolding.cpp:1.124   Wed Jan  3 19:56:39 2007
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Jan  3 20:13:20 2007
@@ -744,7 +744,7 @@
 return 1;
 }
 
-/// evaluatFCmpeRelation - This function determines if there is anything we can
+/// evaluateFCmpRelation - This function determines if there is anything we can
 /// decide about the two constants provided.  This doesn't need to handle 
simple
 /// things like ConstantFP comparisons, but should instead handle 
ConstantExprs.
 /// If we can determine that the two constants have a particular relation to 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-31 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.122 - 1.123
---
Log message:

Fix a bug in comparison of GEP indices.


---
Diffs of the changes:  (+4 -4)

 ConstantFolding.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.122 
llvm/lib/VMCore/ConstantFolding.cpp:1.123
--- llvm/lib/VMCore/ConstantFolding.cpp:1.122   Sat Dec 30 23:26:44 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec 31 15:43:30 2006
@@ -299,7 +299,7 @@
 if (DestTy == Type::Int32Ty)
   return ConstantInt::get(DestTy, FloatToBits(FP-getValue()));
 assert(DestTy == Type::Int64Ty  
-   Incorrect integer  type for bitcast!);
+   Incorrect integer type for bitcast!);
 return ConstantInt::get(DestTy, DoubleToBits(FP-getValue()));
   }
 }
@@ -705,8 +705,8 @@
 static int IdxCompare(Constant *C1, Constant *C2, const Type *ElTy) {
   if (C1 == C2) return 0;
 
-  // Ok, we found a different index.  Are either of the operands ConstantExprs?
-  // If so, we can't do anything with them.
+  // Ok, we found a different index.  If they are not ConstantInt, we can't do
+  // anything with them.
   if (!isaConstantInt(C1) || !isaConstantInt(C2))
 return -2; // don't know!
 
@@ -716,7 +716,7 @@
 C1 = ConstantExpr::getSExt(C1, Type::Int64Ty);
 
   if (C2-getType() != Type::Int64Ty)
-C1 = ConstantExpr::getSExt(C2, Type::Int64Ty);
+C2 = ConstantExpr::getSExt(C2, Type::Int64Ty);
 
   if (C1 == C2) return 0;  // They are equal
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Function.cpp Instructions.cpp Module.cpp ValueTypes.cpp Verifier.cpp

2006-12-30 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.121 - 1.122
Constants.cpp updated: 1.192 - 1.193
Function.cpp updated: 1.107 - 1.108
Instructions.cpp updated: 1.57 - 1.58
Module.cpp updated: 1.69 - 1.70
ValueTypes.cpp updated: 1.8 - 1.9
Verifier.cpp updated: 1.179 - 1.180
---
Log message:

For PR950: http://llvm.org/PR950 :
Change signed integer type names to unsigned equivalents.


---
Diffs of the changes:  (+82 -137)

 ConstantFolding.cpp |   37 +++-
 Constants.cpp   |  117 +---
 Function.cpp|2 
 Instructions.cpp|   38 +---
 Module.cpp  |   15 +++---
 ValueTypes.cpp  |8 +--
 Verifier.cpp|2 
 7 files changed, 82 insertions(+), 137 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.121 
llvm/lib/VMCore/ConstantFolding.cpp:1.122
--- llvm/lib/VMCore/ConstantFolding.cpp:1.121   Sun Dec 24 12:52:08 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sat Dec 30 23:26:44 2006
@@ -87,7 +87,7 @@
   for (unsigned i = 0; i != SrcNumElts; ++i) {
 uint64_t V =
   DoubleToBits(castConstantFP(CP-getOperand(i))-getValue());
-Constant *C = ConstantInt::get(Type::ULongTy, V);
+Constant *C = ConstantInt::get(Type::Int64Ty, V);
 Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
   }
   return ConstantPacked::get(Result);
@@ -96,7 +96,7 @@
 assert(SrcEltTy-getTypeID() == Type::FloatTyID);
 for (unsigned i = 0; i != SrcNumElts; ++i) {
   uint32_t V = 
FloatToBits(castConstantFP(CP-getOperand(i))-getValue());
-  Constant *C = ConstantInt::get(Type::UIntTy, V);
+  Constant *C = ConstantInt::get(Type::Int32Ty, V);
   Result.push_back(ConstantExpr::getBitCast(C, DstEltTy));
 }
 return ConstantPacked::get(Result);
@@ -132,7 +132,7 @@
 
   // Let CastInst::isEliminableCastPair do the heavy lifting.
   return CastInst::isEliminableCastPair(firstOp, secondOp, SrcTy, MidTy, DstTy,
-Type::ULongTy);
+Type::Int64Ty);
 }
 
 Constant *llvm::ConstantFoldCastInstruction(unsigned opc, const Constant *V,
@@ -217,13 +217,13 @@
 if (const PointerType *PTy = dyn_castPointerType(V-getType()))
   if (const PointerType *DPTy = dyn_castPointerType(DestTy)) {
 std::vectorValue* IdxList;
-IdxList.push_back(Constant::getNullValue(Type::IntTy));
+IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
 const Type *ElTy = PTy-getElementType();
 while (ElTy != DPTy-getElementType()) {
   if (const StructType *STy = dyn_castStructType(ElTy)) {
 if (STy-getNumElements() == 0) break;
 ElTy = STy-getElementType(0);
-IdxList.push_back(Constant::getNullValue(Type::UIntTy));
+IdxList.push_back(Constant::getNullValue(Type::Int32Ty));
   } else if (const SequentialType *STy = 
  dyn_castSequentialType(ElTy)) {
 if (isaPointerType(ElTy)) break;  // Can't index into pointers!
@@ -296,10 +296,10 @@
 if (const ConstantFP *FP = dyn_castConstantFP(V)) {
   // FP - Integral.
   if (DestTy-isIntegral()) {
-if (DestTy == Type::IntTy || DestTy == Type::UIntTy)
+if (DestTy == Type::Int32Ty)
   return ConstantInt::get(DestTy, FloatToBits(FP-getValue()));
-assert((DestTy == Type::LongTy || DestTy == Type::ULongTy) 
-Incorrect integer  type for bitcast!);
+assert(DestTy == Type::Int64Ty  
+   Incorrect integer  type for bitcast!);
 return ConstantInt::get(DestTy, DoubleToBits(FP-getValue()));
   }
 }
@@ -712,16 +712,13 @@
 
   // Ok, we have two differing integer indices.  Sign extend them to be the 
same
   // type.  Long is always big enough, so we use it.
-  if (C1-getType() != Type::LongTy  C1-getType() != Type::ULongTy)
-C1 = ConstantExpr::getSExt(C1, Type::LongTy);
-  else
-C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
-  if (C2-getType() != Type::LongTy  C1-getType() != Type::ULongTy)
-C2 = ConstantExpr::getSExt(C2, Type::LongTy);
-  else
-C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
+  if (C1-getType() != Type::Int64Ty)
+C1 = ConstantExpr::getSExt(C1, Type::Int64Ty);
+
+  if (C2-getType() != Type::Int64Ty)
+C1 = ConstantExpr::getSExt(C2, Type::Int64Ty);
 
-  if (C1 == C2) return 0;  // Are they just differing types?
+  if (C1 == C2) return 0;  // They are equal
 
   // If the type being indexed over is really just a zero sized type, there is
   // no pointer difference being made here.
@@ -1324,7 +1321,7 @@
   if (uint32_t ElSize = ElTy-getPrimitiveSize()) {
 // gep null, C is equal to C*sizeof(nullty).  If nullty is a known llvm
 // type, we can statically fold this.
-Constant *R = ConstantInt::get(Type::UIntTy, 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp ConstantFolding.h

2006-12-24 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.120 - 1.121
ConstantFolding.h updated: 1.51 - 1.52
---
Log message:

Cleanup ConstantFoldCompareInstruction:
1. Make the arguments const like the other ConstantFold* functions.
2. Clean up evaluateFCmpRelation so it makes sense for floating point.
3. Implement the use of evaluateFCmpRelation to fold floating point CEs
4. Shorten a variable name so more things fit on one line.
5. Fix various comments.


---
Diffs of the changes:  (+203 -135)

 ConstantFolding.cpp |  335 +++-
 ConstantFolding.h   |3 
 2 files changed, 203 insertions(+), 135 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.120 
llvm/lib/VMCore/ConstantFolding.cpp:1.121
--- llvm/lib/VMCore/ConstantFolding.cpp:1.120   Sat Dec 23 04:21:26 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec 24 12:52:08 2006
@@ -742,50 +742,61 @@
 /// things like ConstantFP comparisons, but should instead handle 
ConstantExprs.
 /// If we can determine that the two constants have a particular relation to 
 /// each other, we should return the corresponding FCmpInst predicate, 
-/// otherwise return FCmpInst::BAD_FCMP_PREDICATE.
+/// otherwise return FCmpInst::BAD_FCMP_PREDICATE. This is used below in
+/// ConstantFoldCompareInstruction.
 ///
 /// To simplify this code we canonicalize the relation so that the first
-/// operand is always the most complex of the two.  We consider simple
-/// constants (like ConstantFP) to be the simplest, followed by
-/// GlobalValues, followed by ConstantExpr's (the most complex).
-static FCmpInst::Predicate evaluateFCmpRelation(Constant *V1, Constant *V2) {
+/// operand is always the most complex of the two.  We consider ConstantFP
+/// to be the simplest, and ConstantExprs to be the most complex.
+static FCmpInst::Predicate evaluateFCmpRelation(const Constant *V1, 
+const Constant *V2) {
   assert(V1-getType() == V2-getType() 
- Cannot compare different types of values!);
+ Cannot compare values of different types!);
+  // Handle degenerate case quickly
   if (V1 == V2) return FCmpInst::FCMP_OEQ;
 
-  if (!isaConstantExpr(V1)  !isaGlobalValue(V1)) {
-if (!isaGlobalValue(V2)  !isaConstantExpr(V2)) {
-  // We distilled this down to a simple case, use the standard constant
-  // folder.
-  ConstantBool *R = dyn_castConstantBool(
-  ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, V1, V2));
+  if (!isaConstantExpr(V1)) {
+if (!isaConstantExpr(V2)) {
+  // We distilled thisUse the standard constant folder for a few cases
+  ConstantBool *R = 0;
+  Constant *C1 = const_castConstant*(V1);
+  Constant *C2 = const_castConstant*(V2);
+  R = dyn_castConstantBool(
+ ConstantExpr::getFCmp(FCmpInst::FCMP_OEQ, C1, 
C2));
   if (R  R-getValue()) 
 return FCmpInst::FCMP_OEQ;
   R = dyn_castConstantBool(
-  ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, V1, V2));
+ ConstantExpr::getFCmp(FCmpInst::FCMP_OLT, C1, 
C2));
   if (R  R-getValue()) 
 return FCmpInst::FCMP_OLT;
   R = dyn_castConstantBool(
-  ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, V1, V2));
-  if (R  R-getValue()) return FCmpInst::FCMP_OGT;
-  
-  // If we couldn't figure it out, bail.
+ ConstantExpr::getFCmp(FCmpInst::FCMP_OGT, C1, 
C2));
+  if (R  R-getValue()) 
+return FCmpInst::FCMP_OGT;
+
+  // Nothing more we can do
   return FCmpInst::BAD_FCMP_PREDICATE;
 }
 
-// If the first operand is simple, swap operands.
-FCmpInst::Predicate SwappedPredicate = evaluateFCmpRelation(V2, V1);
-if (SwappedPredicate != FCmpInst::BAD_FCMP_PREDICATE)
-  return FCmpInst::getSwappedPredicate(SwappedPredicate);
-
-return FCmpInst::BAD_FCMP_PREDICATE;
+// If the first operand is simple and second is ConstantExpr, swap 
operands.
+FCmpInst::Predicate SwappedRelation = evaluateFCmpRelation(V2, V1);
+if (SwappedRelation != FCmpInst::BAD_FCMP_PREDICATE)
+  return FCmpInst::getSwappedPredicate(SwappedRelation);
+  } else {
+// Ok, the LHS is known to be a constantexpr.  The RHS can be any of a
+// constantexpr or a simple constant.
+const ConstantExpr *CE1 = castConstantExpr(V1);
+switch (CE1-getOpcode()) {
+case Instruction::FPTrunc:
+case Instruction::FPExt:
+case Instruction::UIToFP:
+case Instruction::SIToFP:
+  // We might be able to do something with these but we don't right now.
+  break;
+default:
+  break;
+}
   }
-
-  // Ok, the LHS is known to be a constantexpr.  The RHS can be any of a
-  // constantexpr, a CPR, or a simple constant.
-  // ConstantExpr *CE1 = castConstantExpr(V1);
-  // Constant *CE1Op0 = CE1-getOperand(0);
-
   // There are MANY other foldings 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-23 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.119 - 1.120
---
Log message:

Don't overload var names.


---
Diffs of the changes:  (+4 -4)

 ConstantFolding.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.119 
llvm/lib/VMCore/ConstantFolding.cpp:1.120
--- llvm/lib/VMCore/ConstantFolding.cpp:1.119   Sat Dec 23 00:05:41 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sat Dec 23 04:21:26 2006
@@ -883,11 +883,11 @@
   // null pointer, do the comparison with the pre-casted value.
   if (V2-isNullValue() 
   (isaPointerType(CE1-getType()) || CE1-getType()-isIntegral())) {
-bool isSigned = CE1-getOpcode() == Instruction::ZExt ? false :
+bool sgnd = CE1-getOpcode() == Instruction::ZExt ? false :
   (CE1-getOpcode() == Instruction::SExt ? true :
(CE1-getOpcode() == Instruction::PtrToInt ? false : isSigned));
 return evaluateICmpRelation(
-CE1Op0, Constant::getNullValue(CE1Op0-getType()), isSigned);
+CE1Op0, Constant::getNullValue(CE1Op0-getType()), sgnd);
   }
 
   // If the dest type is a pointer type, and the RHS is a constantexpr cast
@@ -898,11 +898,11 @@
 if (CE2-isCast()  isaPointerType(CE1-getType()) 
 CE1-getOperand(0)-getType() == CE2-getOperand(0)-getType() 
 CE1-getOperand(0)-getType()-isIntegral()) {
-  bool isSigned = CE1-getOpcode() == Instruction::ZExt ? false :
+  bool sgnd = CE1-getOpcode() == Instruction::ZExt ? false :
 (CE1-getOpcode() == Instruction::SExt ? true :
  (CE1-getOpcode() == Instruction::PtrToInt ? false : isSigned));
   return evaluateICmpRelation(CE1-getOperand(0), CE2-getOperand(0),
-  isSigned);
+  sgnd);
 }
   break;
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-18 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.116 - 1.117
---
Log message:

Rewrite ConstantFoldCastInstruction so that it doesn't use any of the
ConstRules. Remove the casting rules from ConstRules and subclasses. This
cleans up ConstantFolding significantly. Passes all tests.


---
Diffs of the changes:  (+50 -219)

 ConstantFolding.cpp |  269 +---
 1 files changed, 50 insertions(+), 219 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.116 
llvm/lib/VMCore/ConstantFolding.cpp:1.117
--- llvm/lib/VMCore/ConstantFolding.cpp:1.116   Sun Dec 17 22:22:56 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Mon Dec 18 21:15:47 2006
@@ -54,21 +54,6 @@
 virtual Constant *lessthan(const Constant *V1, const Constant *V2) const 
=0;
 virtual Constant *equalto(const Constant *V1, const Constant *V2) const = 
0;
 
-// Casting operators.
-virtual Constant *castToBool  (const Constant *V) const = 0;
-virtual Constant *castToSByte (const Constant *V) const = 0;
-virtual Constant *castToUByte (const Constant *V) const = 0;
-virtual Constant *castToShort (const Constant *V) const = 0;
-virtual Constant *castToUShort(const Constant *V) const = 0;
-virtual Constant *castToInt   (const Constant *V) const = 0;
-virtual Constant *castToUInt  (const Constant *V) const = 0;
-virtual Constant *castToLong  (const Constant *V) const = 0;
-virtual Constant *castToULong (const Constant *V) const = 0;
-virtual Constant *castToFloat (const Constant *V) const = 0;
-virtual Constant *castToDouble(const Constant *V) const = 0;
-virtual Constant *castToPointer(const Constant *V,
-const PointerType *Ty) const = 0;
-
 // ConstRules::get - Return an instance of ConstRules for the specified
 // constant operands.
 //
@@ -154,44 +139,6 @@
 return SubClassName::EqualTo((const ArgType *)V1, (const ArgType *)V2);
   }
 
-  // Casting operators.  ick
-  virtual Constant *castToBool(const Constant *V) const {
-return SubClassName::CastToBool((const ArgType*)V);
-  }
-  virtual Constant *castToSByte(const Constant *V) const {
-return SubClassName::CastToSByte((const ArgType*)V);
-  }
-  virtual Constant *castToUByte(const Constant *V) const {
-return SubClassName::CastToUByte((const ArgType*)V);
-  }
-  virtual Constant *castToShort(const Constant *V) const {
-return SubClassName::CastToShort((const ArgType*)V);
-  }
-  virtual Constant *castToUShort(const Constant *V) const {
-return SubClassName::CastToUShort((const ArgType*)V);
-  }
-  virtual Constant *castToInt(const Constant *V) const {
-return SubClassName::CastToInt((const ArgType*)V);
-  }
-  virtual Constant *castToUInt(const Constant *V) const {
-return SubClassName::CastToUInt((const ArgType*)V);
-  }
-  virtual Constant *castToLong(const Constant *V) const {
-return SubClassName::CastToLong((const ArgType*)V);
-  }
-  virtual Constant *castToULong(const Constant *V) const {
-return SubClassName::CastToULong((const ArgType*)V);
-  }
-  virtual Constant *castToFloat(const Constant *V) const {
-return SubClassName::CastToFloat((const ArgType*)V);
-  }
-  virtual Constant *castToDouble(const Constant *V) const {
-return SubClassName::CastToDouble((const ArgType*)V);
-  }
-  virtual Constant *castToPointer(const Constant *V,
-  const PointerType *Ty) const {
-return SubClassName::CastToPointer((const ArgType*)V, Ty);
-  }
 
   
//======//
   // Default noop implementations
@@ -219,21 +166,6 @@
 return 0;
   }
 
-  // Casting operators.  ick
-  static Constant *CastToBool  (const Constant *V) { return 0; }
-  static Constant *CastToSByte (const Constant *V) { return 0; }
-  static Constant *CastToUByte (const Constant *V) { return 0; }
-  static Constant *CastToShort (const Constant *V) { return 0; }
-  static Constant *CastToUShort(const Constant *V) { return 0; }
-  static Constant *CastToInt   (const Constant *V) { return 0; }
-  static Constant *CastToUInt  (const Constant *V) { return 0; }
-  static Constant *CastToLong  (const Constant *V) { return 0; }
-  static Constant *CastToULong (const Constant *V) { return 0; }
-  static Constant *CastToFloat (const Constant *V) { return 0; }
-  static Constant *CastToDouble(const Constant *V) { return 0; }
-  static Constant *CastToPointer(const Constant *,
- const PointerType *) {return 0;}
-
 public:
   virtual ~TemplateRules() {}
 };
@@ -287,25 +219,6 @@
   static Constant *Xor(const ConstantBool *V1, const ConstantBool *V2) {
 return ConstantBool::get(V1-getValue() ^ V2-getValue());
   }
-
-  // Casting operators.  ick
-#define DEF_CAST(TYPE, CLASS, CTYPE) \
-  static Constant *CastTo##TYPE  (const ConstantBool *V) {\
-

Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-18 Thread Chris Lattner

On Dec 18, 2006, at 7:16 PM, Reid Spencer wrote:

 Rewrite ConstantFoldCastInstruction so that it doesn't use any of the
 ConstRules. Remove the casting rules from ConstRules and  
 subclasses. This
 cleans up ConstantFolding significantly. Passes all tests.

Nice!

   case Instruction::UIToFP: {
 +// First, extract the unsigned integer value
 +uint64_t Val;
 +if (isaConstantInt(V))
 +  Val = castConstantIntegral(V)-getZExtValue();
 +else if (const ConstantBool *CB = dyn_castConstantBool(V))
 +  Val = CB-getValue() ? 1 : 0;

ConstantBool is ConstantIntegral.  You should be able to do:

 +if (ConstantIntegral *CI = dyn_castConstantIntegral(V))
 +  Val = CI-getZExtValue();

to handle both cases.

 +// Now generate the equivalent floating point value
 +double dVal = (double) Val;
 +return ConstantFP::get(DestTy, dVal);
 +  }
 +  case Instruction::SIToFP: {
 +// First, extract the signed integer value
 +int64_t Val;
 +if (isaConstantInt(V))
 +  Val = castConstantIntegral(V)-getSExtValue();
 +else if (const ConstantBool *CB = dyn_castConstantBool(V))
 +  Val = CB-getValue() ? -1 : 0;

Likewise.

 +// Now generate the equivalent floating point value
 +double dVal = (double) Val;
 +return ConstantFP::get(DestTy, dVal);
 +  }
case Instruction::ZExt:
 +// Handle trunc directly here if it is a ConstantIntegral.
  if (isaConstantInt(V))
 +  return ConstantInt::get(DestTy, castConstantInt(V)- 
 getZExtValue());
 +else if (const ConstantBool *CB = dyn_castConstantBool(V))
 +  return ConstantInt::get(DestTy, CB-getValue() ? 1 : 0);

Likewise, also, please correct the comment.

 +return 0;
case Instruction::SExt:
  // A SExt always produces a signed value so we need to cast  
 the value
  // now before we try to cast it to the destiniation type.
  if (isaConstantInt(V))
 +  return ConstantInt::get(DestTy, castConstantInt(V)- 
 getSExtValue());
  else if (const ConstantBool *CB = dyn_castConstantBool(V))
 +  return ConstantInt::get(DestTy, CB-getValue() ? -1 : 0);

Likewise.

 +return 0;
case Instruction::Trunc:
  // We just handle trunc directly here.  The code below doesn't  
 work for
  // trunc to bool.
 @@ -896,7 +743,8 @@
return ConstantIntegral::get(DestTy, CI-getZExtValue());
  return 0;
case Instruction::BitCast:
 -if (SrcTy == DestTy) return (Constant*)V; // no-op cast
 +if (SrcTy == DestTy)
 +  return (Constant*)V; // no-op cast

Does this fold (int)4U ?

-Chris



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-18 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.117 - 1.118
---
Log message:

Clean up ConstantFoldCastInstruction.


---
Diffs of the changes:  (+30 -53)

 ConstantFolding.cpp |   83 ++--
 1 files changed, 30 insertions(+), 53 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.117 
llvm/lib/VMCore/ConstantFolding.cpp:1.118
--- llvm/lib/VMCore/ConstantFolding.cpp:1.117   Mon Dec 18 21:15:47 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Dec 19 01:41:40 2006
@@ -680,66 +680,43 @@
   switch (opc) {
   case Instruction::FPTrunc:
   case Instruction::FPExt:
-return ConstantFP::get(DestTy, castConstantFP(V)-getValue());
-  case Instruction::FPToUI: {
-double dVal = castConstantFP(V)-getValue();
-uint64_t iVal = (uint64_t) dVal;
-return ConstantIntegral::get(DestTy, iVal);
-  }
-  case Instruction::FPToSI: {
-double dVal = castConstantFP(V)-getValue();
-int64_t iVal = (int64_t) dVal;
-return ConstantIntegral::get(DestTy, iVal);
-  }
-  case Instruction::IntToPtr: //always treated as unsigned
-if (V-isNullValue())// Is it a FP or Integral null value?
+if (const ConstantFP *FPC = dyn_castConstantFP(V))
+  return ConstantFP::get(DestTy, FPC-getValue());
+return 0; // Can't fold.
+  case Instruction::FPToUI: 
+if (const ConstantFP *FPC = dyn_castConstantFP(V))
+  return ConstantIntegral::get(DestTy,(uint64_t) FPC-getValue());
+return 0; // Can't fold.
+  case Instruction::FPToSI:
+if (const ConstantFP *FPC = dyn_castConstantFP(V))
+  return ConstantIntegral::get(DestTy,(int64_t) FPC-getValue());
+return 0; // Can't fold.
+  case Instruction::IntToPtr:   //always treated as unsigned
+if (V-isNullValue())   // Is it an integral null value?
   return ConstantPointerNull::get(castPointerType(DestTy));
-return 0; // Other pointer types cannot be casted
-  case Instruction::PtrToInt: // always treated as unsigned
-if (V-isNullValue())
+return 0;   // Other pointer types cannot be casted
+  case Instruction::PtrToInt:   // always treated as unsigned
+if (V-isNullValue())   // is it a null pointer value?
   return ConstantIntegral::get(DestTy, 0);
-return 0; // Other pointer types cannot be casted
-  case Instruction::UIToFP: {
-// First, extract the unsigned integer value
-uint64_t Val;
-if (isaConstantInt(V))
-  Val = castConstantIntegral(V)-getZExtValue();
-else if (const ConstantBool *CB = dyn_castConstantBool(V))
-  Val = CB-getValue() ? 1 : 0;
-// Now generate the equivalent floating point value
-double dVal = (double) Val;
-return ConstantFP::get(DestTy, dVal);
-  }
-  case Instruction::SIToFP: {
-// First, extract the signed integer value
-int64_t Val;
-if (isaConstantInt(V))
-  Val = castConstantIntegral(V)-getSExtValue();
-else if (const ConstantBool *CB = dyn_castConstantBool(V))
-  Val = CB-getValue() ? -1 : 0;
-// Now generate the equivalent floating point value
-double dVal = (double) Val;
-return ConstantFP::get(DestTy, dVal);
-  }
+return 0;   // Other pointer types cannot be casted
+  case Instruction::UIToFP:
+if (const ConstantIntegral *CI = dyn_castConstantIntegral(V))
+  return ConstantFP::get(DestTy, double(CI-getZExtValue()));
+return 0;
+  case Instruction::SIToFP:
+if (const ConstantIntegral *CI = dyn_castConstantIntegral(V))
+  return ConstantFP::get(DestTy, double(CI-getSExtValue()));
+return 0;
   case Instruction::ZExt:
-// Handle trunc directly here if it is a ConstantIntegral.
-if (isaConstantInt(V))
-  return ConstantInt::get(DestTy, castConstantInt(V)-getZExtValue());
-else if (const ConstantBool *CB = dyn_castConstantBool(V))
-  return ConstantInt::get(DestTy, CB-getValue() ? 1 : 0);
+if (const ConstantIntegral *CI = dyn_castConstantIntegral(V))
+  return ConstantInt::get(DestTy, CI-getZExtValue());
 return 0;
   case Instruction::SExt:
-// A SExt always produces a signed value so we need to cast the value
-// now before we try to cast it to the destiniation type.
-if (isaConstantInt(V))
-  return ConstantInt::get(DestTy, castConstantInt(V)-getSExtValue());
-else if (const ConstantBool *CB = dyn_castConstantBool(V))
-  return ConstantInt::get(DestTy, CB-getValue() ? -1 : 0);
+if (const ConstantIntegral *CI = dyn_castConstantIntegral(V))
+  return ConstantInt::get(DestTy, CI-getSExtValue());
 return 0;
   case Instruction::Trunc:
-// We just handle trunc directly here.  The code below doesn't work for
-// trunc to bool.
-if (const ConstantInt *CI = dyn_castConstantInt(V))
+if (const ConstantInt *CI = dyn_castConstantInt(V)) // Can't trunc a bool
   return ConstantIntegral::get(DestTy, CI-getZExtValue());
 return 0;
   case 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-17 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.114 - 1.115
---
Log message:

Remove the last use of getUnsignedVersion and getSignedVersion from VMCore.
ConstantInt doesn't care about the sign of the type it represents. It only
cares about the bitwidth so there is no need to make the sign of the type
match the SExt or ZExt constant expression.


---
Diffs of the changes:  (+2 -4)

 ConstantFolding.cpp |6 ++
 1 files changed, 2 insertions(+), 4 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.114 
llvm/lib/VMCore/ConstantFolding.cpp:1.115
--- llvm/lib/VMCore/ConstantFolding.cpp:1.114   Tue Dec 12 17:36:14 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec 17 19:11:03 2006
@@ -875,16 +875,14 @@
 // A ZExt always produces an unsigned value so we need to cast the value
 // now before we try to cast it to the destination type
 if (isaConstantInt(V))
-  V = ConstantInt::get(SrcTy-getUnsignedVersion(), 
-   castConstantIntegral(V)-getZExtValue());
+  V = ConstantInt::get(SrcTy, castConstantIntegral(V)-getZExtValue());
 break;
   case Instruction::SIToFP:
   case Instruction::SExt:
 // A SExt always produces a signed value so we need to cast the value
 // now before we try to cast it to the destiniation type.
 if (isaConstantInt(V))
-  V = ConstantInt::get(SrcTy-getSignedVersion(), 
-   castConstantIntegral(V)-getSExtValue());
+  V = ConstantInt::get(SrcTy, castConstantIntegral(V)-getSExtValue());
 else if (const ConstantBool *CB = dyn_castConstantBool(V))
   V = ConstantInt::get(Type::SByteTy, CB-getValue() ? -1 : 0);
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-17 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.115 - 1.116
---
Log message:

Revert last patch. ConstantInt isn't quite ready for signlessness.


---
Diffs of the changes:  (+4 -2)

 ConstantFolding.cpp |6 --
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.115 
llvm/lib/VMCore/ConstantFolding.cpp:1.116
--- llvm/lib/VMCore/ConstantFolding.cpp:1.115   Sun Dec 17 19:11:03 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec 17 22:22:56 2006
@@ -875,14 +875,16 @@
 // A ZExt always produces an unsigned value so we need to cast the value
 // now before we try to cast it to the destination type
 if (isaConstantInt(V))
-  V = ConstantInt::get(SrcTy, castConstantIntegral(V)-getZExtValue());
+  V = ConstantInt::get(SrcTy-getUnsignedVersion(), 
+   castConstantIntegral(V)-getZExtValue());
 break;
   case Instruction::SIToFP:
   case Instruction::SExt:
 // A SExt always produces a signed value so we need to cast the value
 // now before we try to cast it to the destiniation type.
 if (isaConstantInt(V))
-  V = ConstantInt::get(SrcTy, castConstantIntegral(V)-getSExtValue());
+  V = ConstantInt::get(SrcTy-getSignedVersion(), 
+   castConstantIntegral(V)-getSExtValue());
 else if (const ConstantBool *CB = dyn_castConstantBool(V))
   V = ConstantInt::get(Type::SByteTy, CB-getValue() ? -1 : 0);
   



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp

2006-12-12 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.113 - 1.114
Constants.cpp updated: 1.186 - 1.187
---
Log message:

Replace inferred getCast(V,Ty) calls with more strict variants.
Rename getZeroExtend and getSignExtend to getZExt and getSExt to match
the the casting mnemonics in the rest of LLVM.


---
Diffs of the changes:  (+10 -11)

 ConstantFolding.cpp |9 -
 Constants.cpp   |   12 ++--
 2 files changed, 10 insertions(+), 11 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.113 
llvm/lib/VMCore/ConstantFolding.cpp:1.114
--- llvm/lib/VMCore/ConstantFolding.cpp:1.113   Mon Dec 11 15:27:28 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Dec 12 17:36:14 2006
@@ -743,8 +743,7 @@
 (SrcEltTy-isFloatingPoint()  DstEltTy-isFloatingPoint())) {
   for (unsigned i = 0; i != SrcNumElts; ++i)
 Result.push_back(
-  ConstantExpr::getCast(Instruction::BitCast, CP-getOperand(i), 
-DstEltTy));
+  ConstantExpr::getBitCast(CP-getOperand(i), DstEltTy));
   return ConstantPacked::get(Result);
 }
 
@@ -1148,11 +1147,11 @@
   // Ok, we have two differing integer indices.  Sign extend them to be the 
same
   // type.  Long is always big enough, so we use it.
   if (C1-getType() != Type::LongTy  C1-getType() != Type::ULongTy)
-C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
+C1 = ConstantExpr::getSExt(C1, Type::LongTy);
   else
 C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
   if (C2-getType() != Type::LongTy  C1-getType() != Type::ULongTy)
-C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
+C2 = ConstantExpr::getSExt(C2, Type::LongTy);
   else
 C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
 
@@ -1672,7 +1671,7 @@
 R = ConstantExpr::getSExtOrBitCast(R, Idx0-getType());
 R = ConstantExpr::getMul(R, Idx0); // signed multiply
 // R is a signed integer, C is the GEP pointer so - IntToPtr
-return ConstantExpr::getCast(Instruction::IntToPtr, R, C-getType());
+return ConstantExpr::getIntToPtr(R, C-getType());
   }
 }
   }


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.186 llvm/lib/VMCore/Constants.cpp:1.187
--- llvm/lib/VMCore/Constants.cpp:1.186 Mon Dec 11 23:38:50 2006
+++ llvm/lib/VMCore/Constants.cpp   Tue Dec 12 17:36:14 2006
@@ -1391,8 +1391,8 @@
   case Instruction::PtrToInt:
   case Instruction::IntToPtr:
   case Instruction::BitCast:
-New = ConstantExpr::getCast(
-OldC-getOpcode(), OldC-getOperand(0), NewTy);
+New = ConstantExpr::getCast(OldC-getOpcode(), OldC-getOperand(0), 
+NewTy);
 break;
   case Instruction::Select:
 New = ConstantExpr::getSelectTy(NewTy, OldC-getOperand(0),
@@ -1464,8 +1464,8 @@
   assert(0  Invalid cast opcode);
   break;
 case Instruction::Trunc:return getTrunc(C, Ty);
-case Instruction::ZExt: return getZeroExtend(C, Ty);
-case Instruction::SExt: return getSignExtend(C, Ty);
+case Instruction::ZExt: return getZExt(C, Ty);
+case Instruction::SExt: return getSExt(C, Ty);
 case Instruction::FPTrunc:  return getFPTrunc(C, Ty);
 case Instruction::FPExt:return getFPExtend(C, Ty);
 case Instruction::UIToFP:   return getUIToFP(C, Ty);
@@ -1547,7 +1547,7 @@
   return getFoldedCast(Instruction::Trunc, C, Ty);
 }
 
-Constant *ConstantExpr::getSignExtend(Constant *C, const Type *Ty) {
+Constant *ConstantExpr::getSExt(Constant *C, const Type *Ty) {
   assert(C-getType()-isIntegral()  SEXt operand must be integral);
   assert(Ty-isInteger()  SExt produces only integer);
   assert(C-getType()-getPrimitiveSizeInBits()  
Ty-getPrimitiveSizeInBits()
@@ -1556,7 +1556,7 @@
   return getFoldedCast(Instruction::SExt, C, Ty);
 }
 
-Constant *ConstantExpr::getZeroExtend(Constant *C, const Type *Ty) {
+Constant *ConstantExpr::getZExt(Constant *C, const Type *Ty) {
   assert(C-getType()-isIntegral()  ZEXt operand must be integral);
   assert(Ty-isInteger()  ZExt produces only integer);
   assert(C-getType()-getPrimitiveSizeInBits()  
Ty-getPrimitiveSizeInBits()



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-11 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.111 - 1.112
---
Log message:

Implement correct constant folding of bitcast.  This implements  
Transforms/ConstProp/bitcast.ll and fixes 
SingleSource/Regression/C/2003-10-12-GlobalVarInitializers



---
Diffs of the changes:  (+33 -15)

 ConstantFolding.cpp |   48 +---
 1 files changed, 33 insertions(+), 15 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.111 
llvm/lib/VMCore/ConstantFolding.cpp:1.112
--- llvm/lib/VMCore/ConstantFolding.cpp:1.111   Sun Dec 10 20:16:58 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Mon Dec 11 12:30:27 2006
@@ -828,10 +828,6 @@
 const Type *DestTy) {
   const Type *SrcTy = V-getType();
 
-  // Handle some simple cases
-  if (SrcTy == DestTy) 
-return (Constant*)V; // no-op cast
-
   if (isaUndefValue(V))
 return UndefValue::get(DestTy);
 
@@ -901,6 +897,8 @@
   return ConstantIntegral::get(DestTy, CI-getZExtValue());
 return 0;
   case Instruction::BitCast:
+if (SrcTy == DestTy) return (Constant*)V; // no-op cast
+
 // Check to see if we are casting a pointer to an aggregate to a pointer to
 // the first element.  If so, return the appropriate GEP instruction.
 if (const PointerType *PTy = dyn_castPointerType(V-getType()))
@@ -960,18 +958,38 @@
   }
 }
 
-// Handle sign conversion for integer no-op casts. We need to cast the
-// value to the correct signedness before we try to cast it to the
-// destination type. Be careful to do this only for integer types.
-if (isaConstantIntegral(V)  SrcTy-isInteger()) {
-  if (SrcTy-isSigned())
-V = ConstantInt::get(SrcTy-getUnsignedVersion(), 
- castConstantIntegral(V)-getZExtValue());
-   else 
-V = ConstantInt::get(SrcTy-getSignedVersion(), 
- castConstantIntegral(V)-getSExtValue());
+// Finally, implement bitcast folding now.   The code below doesn't handle
+// bitcast right.
+if (isaConstantPointerNull(V))  // ptr-ptr cast.
+  return ConstantPointerNull::get(castPointerType(DestTy));
+
+// Handle integral constant input.
+if (const ConstantInt *CI = dyn_castConstantInt(V)) {
+  // Integral - Integral, must be changing sign.
+  if (DestTy-isIntegral())
+return ConstantInt::get(DestTy, CI-getZExtValue());
+
+  if (DestTy-isFloatingPoint()) {
+if (DestTy == Type::FloatTy)
+  return ConstantFP::get(DestTy, BitsToFloat(CI-getZExtValue()));
+assert(DestTy == Type::DoubleTy  Unknown FP type!);
+return ConstantFP::get(DestTy, BitsToDouble(CI-getZExtValue()));
+  }
+  // Otherwise, can't fold this (packed?)
+  return 0;
 }
-break;
+  
+// Handle ConstantFP input.
+if (const ConstantFP *FP = dyn_castConstantFP(V)) {
+  // FP - Integral.
+  if (DestTy-isIntegral()) {
+if (DestTy == Type::FloatTy)
+  return ConstantInt::get(DestTy, FloatToBits(FP-getValue()));
+assert(DestTy == Type::DoubleTy  Unknown FP type!);
+return ConstantInt::get(DestTy, DoubleToBits(FP-getValue()));
+  }
+}
+return 0;
   default:
 assert(!Invalid CE CastInst opcode);
 break;



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-11 Thread Chris Lattner
Thanks Reid!

-Chris

On Dec 11, 2006, at 1:27 PM, Reid Spencer wrote:



 Changes in directory llvm/lib/VMCore:

 ConstantFolding.cpp updated: 1.112 - 1.113
 ---
 Log message:

 Fix constant folding of FP-int due to cut  paste error in last  
 commit.


 ---
 Diffs of the changes:  (+3 -2)

  ConstantFolding.cpp |5 +++--
  1 files changed, 3 insertions(+), 2 deletions(-)


 Index: llvm/lib/VMCore/ConstantFolding.cpp
 diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.112 llvm/lib/VMCore/ 
 ConstantFolding.cpp:1.113
 --- llvm/lib/VMCore/ConstantFolding.cpp:1.112 Mon Dec 11 12:30:27 2006
 +++ llvm/lib/VMCore/ConstantFolding.cpp   Mon Dec 11 15:27:28 2006
 @@ -983,9 +983,10 @@
  if (const ConstantFP *FP = dyn_castConstantFP(V)) {
// FP - Integral.
if (DestTy-isIntegral()) {
 -if (DestTy == Type::FloatTy)
 +if (DestTy == Type::IntTy || DestTy == Type::UIntTy)
return ConstantInt::get(DestTy, FloatToBits(FP-getValue 
 ()));
 -assert(DestTy == Type::DoubleTy  Unknown FP type!);
 +assert((DestTy == Type::LongTy || DestTy == Type::ULongTy)
 +Incorrect integer  type for bitcast!);
  return ConstantInt::get(DestTy, DoubleToBits(FP-getValue 
 ()));
}
  }



 ___
 llvm-commits mailing list
 llvm-commits@cs.uiuc.edu
 http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-11 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.112 - 1.113
---
Log message:

Fix constant folding of FP-int due to cut  paste error in last commit.


---
Diffs of the changes:  (+3 -2)

 ConstantFolding.cpp |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.112 
llvm/lib/VMCore/ConstantFolding.cpp:1.113
--- llvm/lib/VMCore/ConstantFolding.cpp:1.112   Mon Dec 11 12:30:27 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Mon Dec 11 15:27:28 2006
@@ -983,9 +983,10 @@
 if (const ConstantFP *FP = dyn_castConstantFP(V)) {
   // FP - Integral.
   if (DestTy-isIntegral()) {
-if (DestTy == Type::FloatTy)
+if (DestTy == Type::IntTy || DestTy == Type::UIntTy)
   return ConstantInt::get(DestTy, FloatToBits(FP-getValue()));
-assert(DestTy == Type::DoubleTy  Unknown FP type!);
+assert((DestTy == Type::LongTy || DestTy == Type::ULongTy) 
+Incorrect integer  type for bitcast!);
 return ConstantInt::get(DestTy, DoubleToBits(FP-getValue()));
   }
 }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-04 Thread Chris Lattner

 --- llvm/lib/VMCore/ConstantFolding.cpp:1.105 Fri Dec  1 13:50:54 2006
 +++ llvm/lib/VMCore/ConstantFolding.cpp   Sun Dec  3 20:45:43 2006
 @@ -777,7 +777,8 @@
  uint64_t V =
DoubleToBits(castConstantFP(CP-getOperand(i))- 
 getValue());
  Constant *C = ConstantInt::get(Type::ULongTy, V);
 -Result.push_back(ConstantExpr::getCast(C, DstEltTy));
 +Result.push_back(
 +ConstantExpr::getInferredCast(C, false, DstEltTy,  
 false));
}
return ConstantPacked::get(Result);
  }

This is always a bitcast.

 @@ -786,7 +787,8 @@
  for (unsigned i = 0; i != SrcNumElts; ++i) {
uint32_t V = FloatToBits(castConstantFP(CP-getOperand(i))- 
 getValue());
Constant *C = ConstantInt::get(Type::UIntTy, V);
 -  Result.push_back(ConstantExpr::getCast(C, DstEltTy));
 +  Result.push_back(
 +ConstantExpr::getInferredCast(C, false, DstEltTy, false));
  }
  return ConstantPacked::get(Result);
}

Likewise.

 @@ -853,6 +854,7 @@
break;
  }
if (isAllNull)
 +// This is casting one pointer type to another, always  
 BitCast
  return ConstantExpr::getCast(CE-getOperand(0), DestTy);
  }
}

If so, why not create a bitcast explicitly?

BTW, if you want to add ConstantExpr::getBitCast (and friends) to  
make it easier to do this, go for it.

 @@ -1632,9 +1634,13 @@
  // gep null, C is equal to C*sizeof(nullty).  If nullty is  
 a known llvm
  // type, we can statically fold this.
  Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
 -R = ConstantExpr::getCast(R, Idx0-getType());
 -R = ConstantExpr::getMul(R, Idx0);
 -return ConstantExpr::getCast(R, C-getType());
 +// We know R is unsigned, Idx0 is signed because it must  
 be an index
 +// through a sequential type (gep pointer operand) which  
 is always
 +// signed.
 +R = ConstantExpr::getInferredCast(R, false, Idx0-getType 
 (), true);
 +R = ConstantExpr::getMul(R, Idx0); // signed multiply
 +// R is a signed integer, C is the GEP pointer so - IntToPtr
 +return ConstantExpr::getCast(Instruction::IntToPtr, R, C- 
 getType());
}
  }
}

Please consider using ConstantExpr::getZExtOrBitCast (as I just  
emailed to llvm commits).

 @@ -1662,11 +1668,16 @@
  // Otherwise it must be an array.
  if (!Idx0-isNullValue()) {
const Type *IdxTy = Combined-getType();
 -  if (IdxTy != Idx0-getType()) IdxTy = Type::LongTy;
 -  Combined =
 -ConstantExpr::get(Instruction::Add,
 -  ConstantExpr::getCast(Idx0, IdxTy),
 -  ConstantExpr::getCast(Combined,  
 IdxTy));
 +  if (IdxTy != Idx0-getType()) {
 +Constant *C1 = ConstantExpr::getInferredCast(
 +Idx0, true, Type::LongTy, true);
 +Constant *C2 = ConstantExpr::getInferredCast(
 +Combined, true, Type::LongTy, true);
 +Combined = ConstantExpr::get(Instruction::Add, C1, C2);

Please use:
ConstantExpr::getSExtOrBitCast

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-04 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.107 - 1.108
---
Log message:

Remove the last inferred casts from VMCore.


---
Diffs of the changes:  (+7 -10)

 ConstantFolding.cpp |   17 +++--
 1 files changed, 7 insertions(+), 10 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.107 
llvm/lib/VMCore/ConstantFolding.cpp:1.108
--- llvm/lib/VMCore/ConstantFolding.cpp:1.107   Sun Dec  3 23:19:34 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Mon Dec  4 21:30:09 2006
@@ -777,8 +777,7 @@
 uint64_t V =
   DoubleToBits(castConstantFP(CP-getOperand(i))-getValue());
 Constant *C = ConstantInt::get(Type::ULongTy, V);
-Result.push_back(
-ConstantExpr::getInferredCast(C, false, DstEltTy, false));
+Result.push_back(ConstantExpr::getTruncOrBitCast(C, DstEltTy ));
   }
   return ConstantPacked::get(Result);
 }
@@ -787,8 +786,7 @@
 for (unsigned i = 0; i != SrcNumElts; ++i) {
   uint32_t V = 
FloatToBits(castConstantFP(CP-getOperand(i))-getValue());
   Constant *C = ConstantInt::get(Type::UIntTy, V);
-  Result.push_back(
-ConstantExpr::getInferredCast(C, false, DstEltTy, false));
+  Result.push_back(ConstantExpr::getTruncOrBitCast(C, DstEltTy));
 }
 return ConstantPacked::get(Result);
   }
@@ -855,7 +853,7 @@
 }
   if (isAllNull)
 // This is casting one pointer type to another, always BitCast
-return ConstantExpr::getCast(CE-getOperand(0), DestTy);
+return ConstantExpr::getPointerCast(CE-getOperand(0), DestTy);
 }
   }
 
@@ -1644,7 +1642,7 @@
 // We know R is unsigned, Idx0 is signed because it must be an index
 // through a sequential type (gep pointer operand) which is always
 // signed.
-R = ConstantExpr::getInferredCast(R, false, Idx0-getType(), true);
+R = ConstantExpr::getSExtOrBitCast(R, Idx0-getType());
 R = ConstantExpr::getMul(R, Idx0); // signed multiply
 // R is a signed integer, C is the GEP pointer so - IntToPtr
 return ConstantExpr::getCast(Instruction::IntToPtr, R, C-getType());
@@ -1676,10 +1674,9 @@
 if (!Idx0-isNullValue()) {
   const Type *IdxTy = Combined-getType();
   if (IdxTy != Idx0-getType()) {
-Constant *C1 = ConstantExpr::getInferredCast(
-Idx0, true, Type::LongTy, true);
-Constant *C2 = ConstantExpr::getInferredCast(
-Combined, true, Type::LongTy, true);
+Constant *C1 = ConstantExpr::getSExtOrBitCast(Idx0, Type::LongTy);
+Constant *C2 = ConstantExpr::getSExtOrBitCast(Combined, 
+  Type::LongTy);
 Combined = ConstantExpr::get(Instruction::Add, C1, C2);
   } else {
 Combined =



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-04 Thread Chris Lattner
 Index: llvm/lib/VMCore/ConstantFolding.cpp
 diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.107 llvm/lib/VMCore/ 
 ConstantFolding.cpp:1.108
 --- llvm/lib/VMCore/ConstantFolding.cpp:1.107 Sun Dec  3 23:19:34 2006
 +++ llvm/lib/VMCore/ConstantFolding.cpp   Mon Dec  4 21:30:09 2006
 @@ -777,8 +777,7 @@
  uint64_t V =
DoubleToBits(castConstantFP(CP-getOperand(i))- 
 getValue());
  Constant *C = ConstantInt::get(Type::ULongTy, V);
 -Result.push_back(
 -ConstantExpr::getInferredCast(C, false, DstEltTy,  
 false));
 +Result.push_back(ConstantExpr::getTruncOrBitCast(C,  
 DstEltTy ));
}
return ConstantPacked::get(Result);
  }
 @@ -787,8 +786,7 @@
  for (unsigned i = 0; i != SrcNumElts; ++i) {
uint32_t V = FloatToBits(castConstantFP(CP-getOperand(i))- 
 getValue());
Constant *C = ConstantInt::get(Type::UIntTy, V);
 -  Result.push_back(
 -ConstantExpr::getInferredCast(C, false, DstEltTy, false));
 +  Result.push_back(ConstantExpr::getTruncOrBitCast(C, DstEltTy));
  }
  return ConstantPacked::get(Result);
}

Again, these should only be bitcast.  They can never be truncates.

 @@ -855,7 +853,7 @@
  }
if (isAllNull)
  // This is casting one pointer type to another, always  
 BitCast
 -return ConstantExpr::getCast(CE-getOperand(0), DestTy);
 +return ConstantExpr::getPointerCast(CE-getOperand(0),  
 DestTy);
  }
}

Likewise.

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-04 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.108 - 1.109
---
Log message:

Can't make these fail now with just BitCast. Previous failures must have
been in conjunction with something else. By right, they should just be
BitCasts. 


---
Diffs of the changes:  (+2 -2)

 ConstantFolding.cpp |4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.108 
llvm/lib/VMCore/ConstantFolding.cpp:1.109
--- llvm/lib/VMCore/ConstantFolding.cpp:1.108   Mon Dec  4 21:30:09 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Dec  5 01:18:07 2006
@@ -777,7 +777,7 @@
 uint64_t V =
   DoubleToBits(castConstantFP(CP-getOperand(i))-getValue());
 Constant *C = ConstantInt::get(Type::ULongTy, V);
-Result.push_back(ConstantExpr::getTruncOrBitCast(C, DstEltTy ));
+Result.push_back(ConstantExpr::getBitCast(C, DstEltTy ));
   }
   return ConstantPacked::get(Result);
 }
@@ -786,7 +786,7 @@
 for (unsigned i = 0; i != SrcNumElts; ++i) {
   uint32_t V = 
FloatToBits(castConstantFP(CP-getOperand(i))-getValue());
   Constant *C = ConstantInt::get(Type::UIntTy, V);
-  Result.push_back(ConstantExpr::getTruncOrBitCast(C, DstEltTy));
+  Result.push_back(ConstantExpr::getBitCast(C, DstEltTy));
 }
 return ConstantPacked::get(Result);
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-03 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.105 - 1.106
---
Log message:

Change inferred casts to explicit casts.


---
Diffs of the changes:  (+23 -12)

 ConstantFolding.cpp |   35 +++
 1 files changed, 23 insertions(+), 12 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.105 
llvm/lib/VMCore/ConstantFolding.cpp:1.106
--- llvm/lib/VMCore/ConstantFolding.cpp:1.105   Fri Dec  1 13:50:54 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Dec  3 20:45:43 2006
@@ -777,7 +777,8 @@
 uint64_t V =
   DoubleToBits(castConstantFP(CP-getOperand(i))-getValue());
 Constant *C = ConstantInt::get(Type::ULongTy, V);
-Result.push_back(ConstantExpr::getCast(C, DstEltTy));
+Result.push_back(
+ConstantExpr::getInferredCast(C, false, DstEltTy, false));
   }
   return ConstantPacked::get(Result);
 }
@@ -786,7 +787,8 @@
 for (unsigned i = 0; i != SrcNumElts; ++i) {
   uint32_t V = 
FloatToBits(castConstantFP(CP-getOperand(i))-getValue());
   Constant *C = ConstantInt::get(Type::UIntTy, V);
-  Result.push_back(ConstantExpr::getCast(C, DstEltTy));
+  Result.push_back(
+ConstantExpr::getInferredCast(C, false, DstEltTy, false));
 }
 return ConstantPacked::get(Result);
   }
@@ -839,8 +841,7 @@
   // do to try to simplify it.
   if (const ConstantExpr *CE = dyn_castConstantExpr(V)) {
 if (CE-isCast()) {
-  // Try hard to fold cast of cast because they are almost always
-  // eliminable.
+  // Try hard to fold cast of cast because they are often eliminable.
   if (unsigned newOpc = foldConstantCastPair(opc, CE, DestTy))
 return ConstantExpr::getCast(newOpc, CE-getOperand(0), DestTy);
 } else if (CE-getOpcode() == Instruction::GetElementPtr) {
@@ -853,6 +854,7 @@
   break;
 }
   if (isAllNull)
+// This is casting one pointer type to another, always BitCast
 return ConstantExpr::getCast(CE-getOperand(0), DestTy);
 }
   }
@@ -1632,9 +1634,13 @@
 // gep null, C is equal to C*sizeof(nullty).  If nullty is a known llvm
 // type, we can statically fold this.
 Constant *R = ConstantInt::get(Type::UIntTy, ElSize);
-R = ConstantExpr::getCast(R, Idx0-getType());
-R = ConstantExpr::getMul(R, Idx0);
-return ConstantExpr::getCast(R, C-getType());
+// We know R is unsigned, Idx0 is signed because it must be an index
+// through a sequential type (gep pointer operand) which is always
+// signed.
+R = ConstantExpr::getInferredCast(R, false, Idx0-getType(), true);
+R = ConstantExpr::getMul(R, Idx0); // signed multiply
+// R is a signed integer, C is the GEP pointer so - IntToPtr
+return ConstantExpr::getCast(Instruction::IntToPtr, R, C-getType());
   }
 }
   }
@@ -1662,11 +1668,16 @@
 // Otherwise it must be an array.
 if (!Idx0-isNullValue()) {
   const Type *IdxTy = Combined-getType();
-  if (IdxTy != Idx0-getType()) IdxTy = Type::LongTy;
-  Combined =
-ConstantExpr::get(Instruction::Add,
-  ConstantExpr::getCast(Idx0, IdxTy),
-  ConstantExpr::getCast(Combined, IdxTy));
+  if (IdxTy != Idx0-getType()) {
+Constant *C1 = ConstantExpr::getInferredCast(
+Idx0, true, Type::LongTy, true);
+Constant *C2 = ConstantExpr::getInferredCast(
+Combined, true, Type::LongTy, true);
+Combined = ConstantExpr::get(Instruction::Add, C1, C2);
+  } else {
+Combined =
+  ConstantExpr::get(Instruction::Add, Idx0, Combined);
+  }
 }
 
 NewIndices.push_back(Combined);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-01 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.103 - 1.104
---
Log message:

this logic is broken for trunc to bool, replace the folding logic for trunc
completely, as it is trivial.  We should probably do this for the rest of the
cast operations.  This fixes ConstProp/2006-12-01-TruncBoolBug.ll.



---
Diffs of the changes:  (+8 -5)

 ConstantFolding.cpp |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.103 
llvm/lib/VMCore/ConstantFolding.cpp:1.104
--- llvm/lib/VMCore/ConstantFolding.cpp:1.103   Thu Nov 30 23:55:25 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Dec  1 13:22:41 2006
@@ -860,10 +860,10 @@
   // We actually have to do a cast now, but first, we might need to fix up
   // the value of the operand.
   switch (opc) {
+  case Instruction::PtrToInt:
   case Instruction::FPTrunc:
-  case Instruction::Trunc:
   case Instruction::FPExt:
-break; // floating point input  output, no fixup needed
+break;
   case Instruction::FPToUI: {
 ConstRules Rules = ConstRules::get(V, V);
 V = Rules.castToULong(V); // make sure we get an unsigned value first 
@@ -891,9 +891,12 @@
   V = ConstantInt::get(SrcTy-getSignedVersion(), 
castConstantIntegral(V)-getSExtValue());
 break;
-
-  case Instruction::PtrToInt:
-break;
+  case Instruction::Trunc:
+// We just handle trunc directly here.  The code below doesn't work for
+// trunc to bool.
+if (const ConstantInt *CI = dyn_castConstantInt(V))
+  return ConstantIntegral::get(DestTy, CI-getZExtValue());
+return 0;
   case Instruction::BitCast:
 // Check to see if we are casting a pointer to an aggregate to a pointer to
 // the first element.  If so, return the appropriate GEP instruction.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-12-01 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.104 - 1.105
---
Log message:

These should be rewritten to fold without using the 'Rules' mechanism, but
until this happens at least make sext from bool and sitofp from bool do the
right thing.


---
Diffs of the changes:  (+3 -0)

 ConstantFolding.cpp |3 +++
 1 files changed, 3 insertions(+)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.104 
llvm/lib/VMCore/ConstantFolding.cpp:1.105
--- llvm/lib/VMCore/ConstantFolding.cpp:1.104   Fri Dec  1 13:22:41 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Dec  1 13:50:54 2006
@@ -890,6 +890,9 @@
 if (isaConstantInt(V))
   V = ConstantInt::get(SrcTy-getSignedVersion(), 
castConstantIntegral(V)-getSExtValue());
+else if (const ConstantBool *CB = dyn_castConstantBool(V))
+  V = ConstantInt::get(Type::SByteTy, CB-getValue() ? -1 : 0);
+  
 break;
   case Instruction::Trunc:
 // We just handle trunc directly here.  The code below doesn't work for



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-11-30 Thread Chris Lattner
Reid,

On Nov 30, 2006, at 4:25 PM, Anton Korobeynikov wrote:
 Introducing external weak linkage. Darwin codegen should be added  
 later.

 Index: llvm/lib/VMCore/ConstantFolding.cpp
 diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.100 llvm/lib/VMCore/ 
 ConstantFolding.cpp:1.101
 --- llvm/lib/VMCore/ConstantFolding.cpp:1.100 Sun Nov 26 19:05:10 2006
 +++ llvm/lib/VMCore/ConstantFolding.cpp   Thu Nov 30 18:25:12 2006
 @@ -894,11 +894,8 @@

case Instruction::PtrToInt:
  // Cast of a global address to boolean is always true.
 -if (isaGlobalValue(V)) {
 -  if (DestTy == Type::BoolTy)
 -// FIXME: When we support 'external weak' references, we  
 have to
 -// prevent this transformation from happening.  This code  
 will need
 -// to be updated to ignore external weak symbols when we  
 support it.
 +if (const GlobalValue *GV = dyn_castGlobalValue(V)) {
 +  if (DestTy == Type::BoolTy  !GV-hasExternalWeakLinkage())
  return ConstantBool::getTrue();


This code is wrong, but it's not anton's fault.  This is fallout from  
the cast patch.  ptrtoint(GV, bool) is not guaranteed to be true,  
even with non-extern-weak symbols, as the ptrtoint truncates, it  
doesn't compare to null any more.

This code should be removed, and code should be added to  
ConstantFolding.cpp in the setne(GV, null)/seteq(GV, null) codepath  
to handle this.

Thanks,

-Chris


___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-11-30 Thread Reid Spencer
On Thu, 2006-11-30 at 17:33 -0800, Chris Lattner wrote:
 Reid,
 
 On Nov 30, 2006, at 4:25 PM, Anton Korobeynikov wrote:
  Introducing external weak linkage. Darwin codegen should be added  
  later.
 
  Index: llvm/lib/VMCore/ConstantFolding.cpp
  diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.100 llvm/lib/VMCore/ 
  ConstantFolding.cpp:1.101
  --- llvm/lib/VMCore/ConstantFolding.cpp:1.100   Sun Nov 26 19:05:10 2006
  +++ llvm/lib/VMCore/ConstantFolding.cpp Thu Nov 30 18:25:12 2006
  @@ -894,11 +894,8 @@
 
 case Instruction::PtrToInt:
   // Cast of a global address to boolean is always true.
  -if (isaGlobalValue(V)) {
  -  if (DestTy == Type::BoolTy)
  -// FIXME: When we support 'external weak' references, we  
  have to
  -// prevent this transformation from happening.  This code  
  will need
  -// to be updated to ignore external weak symbols when we  
  support it.
  +if (const GlobalValue *GV = dyn_castGlobalValue(V)) {
  +  if (DestTy == Type::BoolTy  !GV-hasExternalWeakLinkage())
   return ConstantBool::getTrue();
 
 
 This code is wrong, but it's not anton's fault.  This is fallout from  
 the cast patch.  ptrtoint(GV, bool) is not guaranteed to be true,  
 even with non-extern-weak symbols, as the ptrtoint truncates, it  
 doesn't compare to null any more.
 
 This code should be removed, 

Okay, I agree. It should be removed.

 and code should be added to  
 ConstantFolding.cpp in the setne(GV, null)/seteq(GV, null) codepath  
 to handle this.

Which code path?  You mean you generally want a setne(GV, null) to be
folded to ConstBool::True and seteq(GV, null) to be folded to
ConstBool::False ?

 
 Thanks,
 
 -Chris
 
 

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-11-30 Thread Chris Lattner

 and code should be added to
 ConstantFolding.cpp in the setne(GV, null)/seteq(GV, null) codepath
 to handle this.

 Which code path?  You mean you generally want a setne(GV, null) to be
 folded to ConstBool::True and seteq(GV, null) to be folded to
 ConstBool::False ?

Yep exactly.  Unless the global is external weak.

-Chris

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


Re: [llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-11-30 Thread Chris Lattner

On Nov 30, 2006, at 9:01 PM, Reid Spencer wrote:

 On Thu, 2006-11-30 at 20:51 -0800, Chris Lattner wrote:
 On Nov 30, 2006, at 7:56 PM, Reid Spencer wrote:


case Instruction::PtrToInt:
 -// Cast of a global address to boolean is always true.
 -if (const GlobalValue *GV = dyn_castGlobalValue(V)) {
 -  if (DestTy == Type::BoolTy  !GV-hasExternalWeakLinkage())
 -return ConstantBool::getTrue();
 -}
  break;

 Thanks Reid, the patch looks great.  I think you can remove this
 empty case now though,

 The default asserts, trying to catch bad opcodes.

Ah, good call, thanks again!

-Chris

___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-11-02 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.96 - 1.97
---
Log message:

Remove unused variables.


---
Diffs of the changes:  (+5 -6)

 ConstantFolding.cpp |   11 +--
 1 files changed, 5 insertions(+), 6 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.96 
llvm/lib/VMCore/ConstantFolding.cpp:1.97
--- llvm/lib/VMCore/ConstantFolding.cpp:1.96Wed Nov  1 19:53:58 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Nov  2 02:18:15 2006
@@ -809,7 +809,7 @@
   if (V-getType() == DestTy) return (Constant*)V;
 
   // Cast of a global address to boolean is always true.
-  if (const GlobalValue *GV = dyn_castGlobalValue(V)) {
+  if (isaGlobalValue(V)) {
 if (DestTy == Type::BoolTy)
   // FIXME: When we support 'external weak' references, we have to prevent
   // this transformation from happening.  This code will need to be updated
@@ -962,7 +962,7 @@
   const ConstantInt *CIdx = dyn_castConstantInt(Idx);
   if (!CIdx) return 0;
   uint64_t idxVal = CIdx-getZExtValue();
-  if (const UndefValue *UVal = dyn_castUndefValue(Val)) {
+  if (isaUndefValue(Val)) { 
 // Insertion of scalar constant into packed undef
 // Optimize away insertion of undef
 if (isaUndefValue(Elt))
@@ -980,8 +980,7 @@
 }
 return ConstantPacked::get(Ops);
   }
-  if (const ConstantAggregateZero *CVal =
-  dyn_castConstantAggregateZero(Val)) {
+  if (isaConstantAggregateZero(Val)) {
 // Insertion of scalar constant into packed aggregate zero
 // Optimize away insertion of zero
 if (Elt-isNullValue())
@@ -1387,7 +1386,7 @@
   }
 
   if (const ConstantExpr *CE1 = dyn_castConstantExpr(V1)) {
-if (const ConstantExpr *CE2 = dyn_castConstantExpr(V2)) {
+if (isaConstantExpr(V2)) {
   // There are many possible foldings we could do here.  We should probably
   // at least fold add of a pointer with an integer into the appropriate
   // getelementptr.  This will improve alias analysis a bit.
@@ -1444,7 +1443,7 @@
   }
 }
 
-  } else if (const ConstantExpr *CE2 = dyn_castConstantExpr(V2)) {
+  } else if (isaConstantExpr(V2)) {
 // If V2 is a constant expr and V1 isn't, flop them around and fold the
 // other way if possible.
 switch (Opcode) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Instruction.cpp Instructions.cpp

2006-11-01 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.95 - 1.96
Constants.cpp updated: 1.168 - 1.169
Instruction.cpp updated: 1.55 - 1.56
Instructions.cpp updated: 1.44 - 1.45
---
Log message:

For PR950: http://llvm.org/PR950 :
Replace the REM instruction with UREM, SREM and FREM.


---
Diffs of the changes:  (+108 -47)

 ConstantFolding.cpp |   92 
 Constants.cpp   |   38 -
 Instruction.cpp |8 +++-
 Instructions.cpp|   17 -
 4 files changed, 108 insertions(+), 47 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.95 
llvm/lib/VMCore/ConstantFolding.cpp:1.96
--- llvm/lib/VMCore/ConstantFolding.cpp:1.95Thu Oct 26 01:15:43 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Nov  1 19:53:58 2006
@@ -40,10 +40,12 @@
 virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *sub(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *urem(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *srem(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *frem(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *udiv(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *sdiv(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *fdiv(const Constant *V1, const Constant *V2) const = 0;
-virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *op_and(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *op_xor(const Constant *V1, const Constant *V2) const = 0;
@@ -117,8 +119,14 @@
   virtual Constant *fdiv(const Constant *V1, const Constant *V2) const {
 return SubClassName::FDiv((const ArgType *)V1, (const ArgType *)V2);
   }
-  virtual Constant *rem(const Constant *V1, const Constant *V2) const {
-return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
+  virtual Constant *urem(const Constant *V1, const Constant *V2) const {
+return SubClassName::URem((const ArgType *)V1, (const ArgType *)V2);
+  }
+  virtual Constant *srem(const Constant *V1, const Constant *V2) const {
+return SubClassName::SRem((const ArgType *)V1, (const ArgType *)V2);
+  }
+  virtual Constant *frem(const Constant *V1, const Constant *V2) const {
+return SubClassName::FRem((const ArgType *)V1, (const ArgType *)V2);
   }
   virtual Constant *op_and(const Constant *V1, const Constant *V2) const {
 return SubClassName::And((const ArgType *)V1, (const ArgType *)V2);
@@ -192,7 +200,9 @@
   static Constant *SDiv(const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *UDiv(const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *FDiv(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Rem (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *URem(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *SRem(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *FRem(const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *And (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *Or  (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *Xor (const ArgType *V1, const ArgType *V2) { return 0; }
@@ -392,8 +402,14 @@
   static Constant *FDiv(const ConstantPacked *V1, const ConstantPacked *V2) {
 return EvalVectorOp(V1, V2, ConstantExpr::getFDiv);
   }
-  static Constant *Rem(const ConstantPacked *V1, const ConstantPacked *V2) {
-return EvalVectorOp(V1, V2, ConstantExpr::getRem);
+  static Constant *URem(const ConstantPacked *V1, const ConstantPacked *V2) {
+return EvalVectorOp(V1, V2, ConstantExpr::getURem);
+  }
+  static Constant *SRem(const ConstantPacked *V1, const ConstantPacked *V2) {
+return EvalVectorOp(V1, V2, ConstantExpr::getSRem);
+  }
+  static Constant *FRem(const ConstantPacked *V1, const ConstantPacked *V2) {
+return EvalVectorOp(V1, V2, ConstantExpr::getFRem);
   }
   static Constant *And(const ConstantPacked *V1, const ConstantPacked *V2) {
 return EvalVectorOp(V1, V2, ConstantExpr::getAnd);
@@ -510,30 +526,36 @@
 #undef DEF_CAST
 
   static Constant *UDiv(const ConstantInt *V1, const ConstantInt *V2) {
-if (V2-isNullValue()) 
+if (V2-isNullValue())   // X / 0
   return 0;
 BuiltinType R = (BuiltinType)(V1-getZExtValue() / V2-getZExtValue());
 return ConstantInt::get(*Ty, R);
   }
 
   static Constant *SDiv(const ConstantInt *V1, const ConstantInt *V2) {
-if (V2-isNullValue()) 
+if (V2-isNullValue())   // X / 0
   return 0;
   

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Instruction.cpp Instructions.cpp

2006-10-26 Thread Reid Spencer


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.94 - 1.95
Constants.cpp updated: 1.165 - 1.166
Instruction.cpp updated: 1.53 - 1.54
Instructions.cpp updated: 1.43 - 1.44
---
Log message:

For PR950: http://llvm.org/PR950 :
Make necessary changes to support DIV - [SUF]Div. This changes llvm to
have three division instructions: signed, unsigned, floating point. The
bytecode and assembler are bacwards compatible, however.


---
Diffs of the changes:  (+105 -33)

 ConstantFolding.cpp |   82 +++-
 Constants.cpp   |   30 ---
 Instruction.cpp |8 +++--
 Instructions.cpp|   18 ++-
 4 files changed, 105 insertions(+), 33 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.94 
llvm/lib/VMCore/ConstantFolding.cpp:1.95
--- llvm/lib/VMCore/ConstantFolding.cpp:1.94Fri Oct 20 02:07:24 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Oct 26 01:15:43 2006
@@ -40,7 +40,9 @@
 virtual Constant *add(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *sub(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *mul(const Constant *V1, const Constant *V2) const = 0;
-virtual Constant *div(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *udiv(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *sdiv(const Constant *V1, const Constant *V2) const = 0;
+virtual Constant *fdiv(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *rem(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *op_and(const Constant *V1, const Constant *V2) const = 0;
 virtual Constant *op_or (const Constant *V1, const Constant *V2) const = 0;
@@ -106,8 +108,14 @@
   virtual Constant *mul(const Constant *V1, const Constant *V2) const {
 return SubClassName::Mul((const ArgType *)V1, (const ArgType *)V2);
   }
-  virtual Constant *div(const Constant *V1, const Constant *V2) const {
-return SubClassName::Div((const ArgType *)V1, (const ArgType *)V2);
+  virtual Constant *udiv(const Constant *V1, const Constant *V2) const {
+return SubClassName::UDiv((const ArgType *)V1, (const ArgType *)V2);
+  }
+  virtual Constant *sdiv(const Constant *V1, const Constant *V2) const {
+return SubClassName::SDiv((const ArgType *)V1, (const ArgType *)V2);
+  }
+  virtual Constant *fdiv(const Constant *V1, const Constant *V2) const {
+return SubClassName::FDiv((const ArgType *)V1, (const ArgType *)V2);
   }
   virtual Constant *rem(const Constant *V1, const Constant *V2) const {
 return SubClassName::Rem((const ArgType *)V1, (const ArgType *)V2);
@@ -178,16 +186,18 @@
   // Default noop implementations
   
//======//
 
-  static Constant *Add(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Sub(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Mul(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Div(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Rem(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *And(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Or (const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Xor(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Shl(const ArgType *V1, const ArgType *V2) { return 0; }
-  static Constant *Shr(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Add (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Sub (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Mul (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *SDiv(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *UDiv(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *FDiv(const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Rem (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *And (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Or  (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Xor (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Shl (const ArgType *V1, const ArgType *V2) { return 0; }
+  static Constant *Shr (const ArgType *V1, const ArgType *V2) { return 0; }
   static Constant *LessThan(const ArgType *V1, const ArgType *V2) {
 return 0;
   }
@@ -373,8 +383,14 @@
   static Constant *Mul(const ConstantPacked *V1, const ConstantPacked *V2) {
 return EvalVectorOp(V1, V2, ConstantExpr::getMul);
   }
-  static Constant *Div(const ConstantPacked *V1, const ConstantPacked *V2) {
-return EvalVectorOp(V1, V2, ConstantExpr::getDiv);
+  static Constant *UDiv(const 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-10-13 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.92 - 1.93
---
Log message:

Fix another dtor issue.  The function local statics in this function were
being destroyed at inconvenient times.  Switch to using non-local ManagedStatic
objects, which actually also speeds up ConstRules::get.


---
Diffs of the changes:  (+42 -32)

 ConstantFolding.cpp |   74 +---
 1 files changed, 42 insertions(+), 32 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.92 
llvm/lib/VMCore/ConstantFolding.cpp:1.93
--- llvm/lib/VMCore/ConstantFolding.cpp:1.92Thu Sep 28 18:34:49 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Oct 13 12:22:21 2006
@@ -23,9 +23,10 @@
 #include llvm/Instructions.h
 #include llvm/DerivedTypes.h
 #include llvm/Function.h
+#include llvm/Support/Compiler.h
 #include llvm/Support/GetElementPtrTypeIterator.h
+#include llvm/Support/ManagedStatic.h
 #include llvm/Support/MathExtras.h
-#include llvm/Support/Compiler.h
 #include limits
 #include cmath
 using namespace llvm;
@@ -584,49 +585,58 @@
 };
 }  // end anonymous namespace
 
+static ManagedStaticEmptyRules   EmptyR;
+static ManagedStaticBoolRulesBoolR;
+static ManagedStaticNullPointerRules NullPointerR;
+static ManagedStaticConstantPackedRules ConstantPackedR;
+static ManagedStaticGeneralPackedRules GeneralPackedR;
+static ManagedStaticDirectIntRulesConstantSInt,   signed char ,
+Type::SByteTy  SByteR;
+static ManagedStaticDirectIntRulesConstantUInt, unsigned char ,
+Type::UByteTy  UByteR;
+static ManagedStaticDirectIntRulesConstantSInt,   signed short,
+Type::ShortTy  ShortR;
+static ManagedStaticDirectIntRulesConstantUInt, unsigned short,
+Type::UShortTy  UShortR;
+static ManagedStaticDirectIntRulesConstantSInt,   signed int  ,
+Type::IntTyIntR;
+static ManagedStaticDirectIntRulesConstantUInt, unsigned int  ,
+Type::UIntTy   UIntR;
+static ManagedStaticDirectIntRulesConstantSInt,  int64_t  ,
+Type::LongTy   LongR;
+static ManagedStaticDirectIntRulesConstantUInt, uint64_t  ,
+Type::ULongTy  ULongR;
+static ManagedStaticDirectFPRules ConstantFP  , float ,
+Type::FloatTy  FloatR;
+static ManagedStaticDirectFPRules ConstantFP  , double,
+Type::DoubleTy  DoubleR;
 
 /// ConstRules::get - This method returns the constant rules implementation 
that
 /// implements the semantics of the two specified constants.
 ConstRules ConstRules::get(const Constant *V1, const Constant *V2) {
-  static EmptyRules   EmptyR;
-  static BoolRulesBoolR;
-  static NullPointerRules NullPointerR;
-  static ConstantPackedRules ConstantPackedR;
-  static GeneralPackedRules GeneralPackedR;
-  static DirectIntRulesConstantSInt,   signed char , Type::SByteTy  SByteR;
-  static DirectIntRulesConstantUInt, unsigned char , Type::UByteTy  UByteR;
-  static DirectIntRulesConstantSInt,   signed short, Type::ShortTy  ShortR;
-  static DirectIntRulesConstantUInt, unsigned short, Type::UShortTy UShortR;
-  static DirectIntRulesConstantSInt,   signed int  , Type::IntTyIntR;
-  static DirectIntRulesConstantUInt, unsigned int  , Type::UIntTy   UIntR;
-  static DirectIntRulesConstantSInt,  int64_t  , Type::LongTy   LongR;
-  static DirectIntRulesConstantUInt, uint64_t  , Type::ULongTy  ULongR;
-  static DirectFPRules ConstantFP  , float , Type::FloatTy  FloatR;
-  static DirectFPRules ConstantFP  , double, Type::DoubleTy DoubleR;
-
   if (isaConstantExpr(V1) || isaConstantExpr(V2) ||
   isaGlobalValue(V1) || isaGlobalValue(V2) ||
   isaUndefValue(V1) || isaUndefValue(V2))
-return EmptyR;
+return *EmptyR;
 
   switch (V1-getType()-getTypeID()) {
   default: assert(0  Unknown value type for constant folding!);
-  case Type::BoolTyID:return BoolR;
-  case Type::PointerTyID: return NullPointerR;
-  case Type::SByteTyID:   return SByteR;
-  case Type::UByteTyID:   return UByteR;
-  case Type::ShortTyID:   return ShortR;
-  case Type::UShortTyID:  return UShortR;
-  case Type::IntTyID: return IntR;
-  case Type::UIntTyID:return UIntR;
-  case Type::LongTyID:return LongR;
-  case Type::ULongTyID:   return ULongR;
-  case Type::FloatTyID:   return FloatR;
-  case Type::DoubleTyID:  return DoubleR;
+  case Type::BoolTyID:return *BoolR;
+  case Type::PointerTyID: return *NullPointerR;
+  case Type::SByteTyID:   return *SByteR;
+  case Type::UByteTyID:   return *UByteR;
+  case Type::ShortTyID:   return *ShortR;
+  case Type::UShortTyID:  return *UShortR;
+  case Type::IntTyID: return *IntR;
+  case 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-09-28 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.91 - 1.92
---
Log message:

Eliminate ConstantBool::True and ConstantBool::False.  Instead, 
provideConstantBool::getTrue() and ConstantBool::getFalse().


---
Diffs of the changes:  (+15 -17)

 ConstantFolding.cpp |   32 +++-
 1 files changed, 15 insertions(+), 17 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.91 
llvm/lib/VMCore/ConstantFolding.cpp:1.92
--- llvm/lib/VMCore/ConstantFolding.cpp:1.91Sun Sep 17 14:14:47 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Sep 28 18:34:49 2006
@@ -225,7 +225,7 @@
 struct VISIBILITY_HIDDEN EmptyRules
   : public TemplateRulesConstant, EmptyRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
-if (V1 == V2) return ConstantBool::True;
+if (V1 == V2) return ConstantBool::getTrue();
 return 0;
   }
 };
@@ -296,10 +296,10 @@
 struct VISIBILITY_HIDDEN NullPointerRules
   : public TemplateRulesConstantPointerNull, NullPointerRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
-return ConstantBool::True;  // Null pointers are always equal
+return ConstantBool::getTrue();  // Null pointers are always equal
   }
   static Constant *CastToBool(const Constant *V) {
-return ConstantBool::False;
+return ConstantBool::getFalse();
   }
   static Constant *CastToSByte (const Constant *V) {
 return ConstantSInt::get(Type::SByteTy, 0);
@@ -729,7 +729,7 @@
   // FIXME: When we support 'external weak' references, we have to prevent
   // this transformation from happening.  This code will need to be updated
   // to ignore external weak symbols when we support it.
-  return ConstantBool::True;
+  return ConstantBool::getTrue();
   } else if (const ConstantExpr *CE = dyn_castConstantExpr(V)) {
 if (CE-getOpcode() == Instruction::Cast) {
   Constant *Op = const_castConstant*(CE-getOperand(0));
@@ -842,10 +842,8 @@
 Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
   const Constant *V1,
   const Constant *V2) {
-  if (Cond == ConstantBool::True)
-return const_castConstant*(V1);
-  else if (Cond == ConstantBool::False)
-return const_castConstant*(V2);
+  if (const ConstantBool *CB = dyn_castConstantBool(Cond))
+return const_castConstant*(CB-getValue() ? V1 : V2);
 
   if (isaUndefValue(V1)) return const_castConstant*(V2);
   if (isaUndefValue(V2)) return const_castConstant*(V1);
@@ -1011,11 +1009,11 @@
   // We distilled this down to a simple case, use the standard constant
   // folder.
   ConstantBool *R = dyn_castConstantBool(ConstantExpr::getSetEQ(V1, V2));
-  if (R == ConstantBool::True) return Instruction::SetEQ;
+  if (R  R-getValue()) return Instruction::SetEQ;
   R = dyn_castConstantBool(ConstantExpr::getSetLT(V1, V2));
-  if (R == ConstantBool::True) return Instruction::SetLT;
+  if (R  R-getValue()) return Instruction::SetLT;
   R = dyn_castConstantBool(ConstantExpr::getSetGT(V1, V2));
-  if (R == ConstantBool::True) return Instruction::SetGT;
+  if (R  R-getValue()) return Instruction::SetGT;
   
   // If we couldn't figure it out, bail.
   return Instruction::BinaryOpsEnd;
@@ -1240,20 +1238,20 @@
Opcode == Instruction::SetGE);
 case Instruction::SetLE:
   // If we know that V1 = V2, we can only partially decide this relation.
-  if (Opcode == Instruction::SetGT) return ConstantBool::False;
-  if (Opcode == Instruction::SetLT) return ConstantBool::True;
+  if (Opcode == Instruction::SetGT) return ConstantBool::getFalse();
+  if (Opcode == Instruction::SetLT) return ConstantBool::getTrue();
   break;
 
 case Instruction::SetGE:
   // If we know that V1 = V2, we can only partially decide this relation.
-  if (Opcode == Instruction::SetLT) return ConstantBool::False;
-  if (Opcode == Instruction::SetGT) return ConstantBool::True;
+  if (Opcode == Instruction::SetLT) return ConstantBool::getFalse();
+  if (Opcode == Instruction::SetGT) return ConstantBool::getTrue();
   break;
 
 case Instruction::SetNE:
   // If we know that V1 != V2, we can only partially decide this relation.
-  if (Opcode == Instruction::SetEQ) return ConstantBool::False;
-  if (Opcode == Instruction::SetNE) return ConstantBool::True;
+  if (Opcode == Instruction::SetEQ) return ConstantBool::getFalse();
+  if (Opcode == Instruction::SetNE) return ConstantBool::getTrue();
   break;
 }
   }



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Instruction.cpp

2006-09-17 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.90 - 1.91
Constants.cpp updated: 1.159 - 1.160
Instruction.cpp updated: 1.52 - 1.53
---
Log message:

Add new SetCondInst::isRelational/isEquality methods.  Rename 
Instruction::isRelational to Instruction::isComparison.


---
Diffs of the changes:  (+5 -5)

 ConstantFolding.cpp |2 +-
 Constants.cpp   |4 ++--
 Instruction.cpp |4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.90 
llvm/lib/VMCore/ConstantFolding.cpp:1.91
--- llvm/lib/VMCore/ConstantFolding.cpp:1.90Sun Aug 27 07:54:02 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Sun Sep 17 14:14:47 2006
@@ -1212,7 +1212,7 @@
   // If we successfully folded the expression, return it now.
   if (C) return C;
 
-  if (SetCondInst::isRelational(Opcode)) {
+  if (SetCondInst::isComparison(Opcode)) {
 if (isaUndefValue(V1) || isaUndefValue(V2))
   return UndefValue::get(Type::BoolTy);
 switch (evaluateRelation(const_castConstant*(V1),


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.159 llvm/lib/VMCore/Constants.cpp:1.160
--- llvm/lib/VMCore/Constants.cpp:1.159 Sun Aug 27 07:54:02 2006
+++ llvm/lib/VMCore/Constants.cpp   Sun Sep 17 14:14:47 2006
@@ -1419,7 +1419,7 @@
   assert(C1-getType() == C2-getType() 
  Operand types in binary constant expression should match);
 
-  if (ReqTy == C1-getType() || (Instruction::isRelational(Opcode) 
+  if (ReqTy == C1-getType() || (Instruction::isComparison(Opcode) 
  ReqTy == Type::BoolTy))
 if (Constant *FC = ConstantFoldBinaryInstruction(Opcode, C1, C2))
   return FC;  // Fold a few common cases...
@@ -1462,7 +1462,7 @@
   }
 #endif
 
-  if (Instruction::isRelational(Opcode))
+  if (Instruction::isComparison(Opcode))
 return getTy(Type::BoolTy, Opcode, C1, C2);
   else
 return getTy(C1-getType(), Opcode, C1, C2);


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.52 
llvm/lib/VMCore/Instruction.cpp:1.53
--- llvm/lib/VMCore/Instruction.cpp:1.52Wed Jun 21 11:53:47 2006
+++ llvm/lib/VMCore/Instruction.cpp Sun Sep 17 14:14:47 2006
@@ -200,9 +200,9 @@
   }
 }
 
-/// isRelational - Return true if the instruction is a Set* instruction:
+/// isComparison - Return true if the instruction is a Set* instruction:
 ///
-bool Instruction::isRelational(unsigned op) {
+bool Instruction::isComparison(unsigned op) {
   switch (op) {
   case SetEQ:
   case SetNE:



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp Constants.cpp Type.cpp Verifier.cpp

2006-06-28 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.88 - 1.89
Constants.cpp updated: 1.154 - 1.155
Type.cpp updated: 1.140 - 1.141
Verifier.cpp updated: 1.156 - 1.157
---
Log message:

Use hidden visibility to reduce the sizes of some .o files.  This chops 60K off 
a release llvm-dis.


---
Diffs of the changes:  (+47 -24)

 ConstantFolding.cpp |   29 +
 Constants.cpp   |   35 +--
 Type.cpp|3 ++-
 Verifier.cpp|4 +++-
 4 files changed, 47 insertions(+), 24 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.88 
llvm/lib/VMCore/ConstantFolding.cpp:1.89
--- llvm/lib/VMCore/ConstantFolding.cpp:1.88Wed Jun 21 13:13:36 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Jun 28 16:38:54 2006
@@ -25,12 +25,13 @@
 #include llvm/Function.h
 #include llvm/Support/GetElementPtrTypeIterator.h
 #include llvm/Support/MathExtras.h
+#include llvm/Support/Visibility.h
 #include limits
 #include cmath
 using namespace llvm;
 
 namespace {
-  struct ConstRules {
+  struct VISIBILITY_HIDDEN ConstRules {
 ConstRules() {}
 virtual ~ConstRules() {}
 
@@ -88,7 +89,7 @@
 //
 namespace {
 templateclass ArgType, class SubClassName
-class TemplateRules : public ConstRules {
+class VISIBILITY_HIDDEN TemplateRules : public ConstRules {
 
 
   
//======//
@@ -221,7 +222,8 @@
 // EmptyRules provides a concrete base class of ConstRules that does nothing
 //
 namespace {
-struct EmptyRules : public TemplateRulesConstant, EmptyRules {
+struct VISIBILITY_HIDDEN EmptyRules
+  : public TemplateRulesConstant, EmptyRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
 if (V1 == V2) return ConstantBool::True;
 return 0;
@@ -238,7 +240,8 @@
 // BoolRules provides a concrete base class of ConstRules for the 'bool' type.
 //
 namespace {
-struct BoolRules : public TemplateRulesConstantBool, BoolRules {
+struct VISIBILITY_HIDDEN BoolRules
+  : public TemplateRulesConstantBool, BoolRules {
 
   static Constant *LessThan(const ConstantBool *V1, const ConstantBool *V2) {
 return ConstantBool::get(V1-getValue()  V2-getValue());
@@ -290,8 +293,8 @@
 // pointers.
 //
 namespace {
-struct NullPointerRules : public TemplateRulesConstantPointerNull,
-   NullPointerRules {
+struct VISIBILITY_HIDDEN NullPointerRules
+  : public TemplateRulesConstantPointerNull, NullPointerRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
 return ConstantBool::True;  // Null pointers are always equal
   }
@@ -357,7 +360,7 @@
 /// ConstantPacked operands.
 ///
 namespace {
-struct ConstantPackedRules
+struct VISIBILITY_HIDDEN ConstantPackedRules
   : public TemplateRulesConstantPacked, ConstantPackedRules {
   
   static Constant *Add(const ConstantPacked *V1, const ConstantPacked *V2) {
@@ -417,7 +420,8 @@
 /// cause for this is that one operand is a ConstantAggregateZero.
 ///
 namespace {
-struct GeneralPackedRules : public TemplateRulesConstant, GeneralPackedRules 
{
+struct VISIBILITY_HIDDEN GeneralPackedRules
+  : public TemplateRulesConstant, GeneralPackedRules {
 };
 }  // end anonymous namespace
 
@@ -432,7 +436,8 @@
 //
 namespace {
 templateclass ConstantClass, class BuiltinType, Type **Ty, class SuperClass
-struct DirectRules : public TemplateRulesConstantClass, SuperClass {
+struct VISIBILITY_HIDDEN DirectRules
+  : public TemplateRulesConstantClass, SuperClass {
   static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
 BuiltinType R = (BuiltinType)V1-getValue() + (BuiltinType)V2-getValue();
 return ConstantClass::get(*Ty, R);
@@ -502,7 +507,7 @@
 //
 namespace {
 template class ConstantClass, class BuiltinType, Type **Ty
-struct DirectIntRules
+struct VISIBILITY_HIDDEN DirectIntRules
   : public DirectRulesConstantClass, BuiltinType, Ty,
DirectIntRulesConstantClass, BuiltinType, Ty  {
 
@@ -560,7 +565,7 @@
 ///
 namespace {
 template class ConstantClass, class BuiltinType, Type **Ty
-struct DirectFPRules
+struct VISIBILITY_HIDDEN DirectFPRules
   : public DirectRulesConstantClass, BuiltinType, Ty,
DirectFPRulesConstantClass, BuiltinType, Ty  {
   static Constant *Rem(const ConstantClass *V1, const ConstantClass *V2) {
@@ -1472,7 +1477,7 @@
   dyn_castPointerType(CE-getOperand(0)-getType()))
 if (const ArrayType *SAT = dyn_castArrayType(SPT-getElementType()))
   if (const ArrayType *CAT =
-  
dyn_castArrayType(castPointerType(C-getType())-getElementType()))
+dyn_castArrayType(castPointerType(C-getType())-getElementType()))
 if (CAT-getElementType() == SAT-getElementType())
   return ConstantExpr::getGetElementPtr(
   (Constant*)CE-getOperand(0), IdxList);



[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-06-21 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.87 - 1.88
---
Log message:

Add more anonymous namespaces to make it clear that these are private classes


---
Diffs of the changes:  (+18 -1)

 ConstantFolding.cpp |   19 ++-
 1 files changed, 18 insertions(+), 1 deletion(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.87 
llvm/lib/VMCore/ConstantFolding.cpp:1.88
--- llvm/lib/VMCore/ConstantFolding.cpp:1.87Fri Apr  7 20:18:18 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Wed Jun 21 13:13:36 2006
@@ -86,6 +86,7 @@
 // This class also provides subclasses with typesafe implementations of methods
 // so that don't have to do type casting.
 //
+namespace {
 templateclass ArgType, class SubClassName
 class TemplateRules : public ConstRules {
 
@@ -210,7 +211,7 @@
 public:
   virtual ~TemplateRules() {}
 };
-
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -219,12 +220,14 @@
 //
 // EmptyRules provides a concrete base class of ConstRules that does nothing
 //
+namespace {
 struct EmptyRules : public TemplateRulesConstant, EmptyRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
 if (V1 == V2) return ConstantBool::True;
 return 0;
   }
 };
+}  // end anonymous namespace
 
 
 
@@ -234,6 +237,7 @@
 //
 // BoolRules provides a concrete base class of ConstRules for the 'bool' type.
 //
+namespace {
 struct BoolRules : public TemplateRulesConstantBool, BoolRules {
 
   static Constant *LessThan(const ConstantBool *V1, const ConstantBool *V2) {
@@ -275,6 +279,7 @@
   DEF_CAST(Double, ConstantFP  , double)
 #undef DEF_CAST
 };
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -284,6 +289,7 @@
 // NullPointerRules provides a concrete base class of ConstRules for null
 // pointers.
 //
+namespace {
 struct NullPointerRules : public TemplateRulesConstantPointerNull,
NullPointerRules {
   static Constant *EqualTo(const Constant *V1, const Constant *V2) {
@@ -328,6 +334,7 @@
 return ConstantPointerNull::get(PTy);
   }
 };
+}  // end anonymous namespace
 
 
//===--===//
 //  ConstantPackedRules Class
@@ -349,6 +356,7 @@
 /// PackedTypeRules provides a concrete base class of ConstRules for
 /// ConstantPacked operands.
 ///
+namespace {
 struct ConstantPackedRules
   : public TemplateRulesConstantPacked, ConstantPackedRules {
   
@@ -397,6 +405,7 @@
 return 0;
   }
 };
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -407,8 +416,10 @@
 /// PackedType operands, where both operands are not ConstantPacked.  The usual
 /// cause for this is that one operand is a ConstantAggregateZero.
 ///
+namespace {
 struct GeneralPackedRules : public TemplateRulesConstant, GeneralPackedRules 
{
 };
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -419,6 +430,7 @@
 // different types.  This allows the C++ compiler to automatically generate our
 // constant handling operations in a typesafe and accurate manner.
 //
+namespace {
 templateclass ConstantClass, class BuiltinType, Type **Ty, class SuperClass
 struct DirectRules : public TemplateRulesConstantClass, SuperClass {
   static Constant *Add(const ConstantClass *V1, const ConstantClass *V2) {
@@ -478,6 +490,7 @@
   DEF_CAST(Double, ConstantFP  , double)
 #undef DEF_CAST
 };
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -487,6 +500,7 @@
 // DirectIntRules provides implementations of functions that are valid on
 // integer types, but not all types in general.
 //
+namespace {
 template class ConstantClass, class BuiltinType, Type **Ty
 struct DirectIntRules
   : public DirectRulesConstantClass, BuiltinType, Ty,
@@ -534,6 +548,7 @@
 return ConstantClass::get(*Ty, R);
   }
 };
+}  // end anonymous namespace
 
 
 
//===--===//
@@ -543,6 +558,7 @@
 /// DirectFPRules provides implementations of functions that are valid on
 /// floating point types, but not all types in general.
 ///
+namespace {
 template class ConstantClass, class BuiltinType, Type **Ty
 struct DirectFPRules
   : public DirectRulesConstantClass, BuiltinType, Ty,
@@ -561,6 +577,7 @@
 return ConstantClass::get(*Ty, R);
   }
 };
+}  // end anonymous namespace
 
 
 /// ConstRules::get - This method returns the constant rules implementation 
that



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-04-06 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.85 - 1.86
---
Log message:

Constant fold extractelement(zero, x) - zero


---
Diffs of the changes:  (+3 -0)

 ConstantFolding.cpp |3 +++
 1 files changed, 3 insertions(+)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.85 
llvm/lib/VMCore/ConstantFolding.cpp:1.86
--- llvm/lib/VMCore/ConstantFolding.cpp:1.85Sat Apr  1 19:38:28 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Apr  6 23:44:06 2006
@@ -836,6 +836,9 @@
   const Constant *Idx) {
   if (isaUndefValue(Val))  // ee(undef, x) - undef
 return UndefValue::get(castPackedType(Val-getType())-getElementType());
+  if (Val-isNullValue())  // ee(zero, x) - zero
+return Constant::getNullValue(
+  castPackedType(Val-getType())-getElementType());
   
   if (const ConstantPacked *CVal = dyn_castConstantPacked(Val)) {
 if (const ConstantUInt *CIdx = dyn_castConstantUInt(Idx)) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-03-31 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.83 - 1.84
---
Log message:

constant fold extractelement with undef operands.


---
Diffs of the changes:  (+7 -1)

 ConstantFolding.cpp |8 +++-
 1 files changed, 7 insertions(+), 1 deletion(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.83 
llvm/lib/VMCore/ConstantFolding.cpp:1.84
--- llvm/lib/VMCore/ConstantFolding.cpp:1.83Tue Jan 17 14:07:22 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Fri Mar 31 12:31:40 2006
@@ -726,11 +726,17 @@
 
 Constant *llvm::ConstantFoldExtractElementInstruction(const Constant *Val,
   const Constant *Idx) {
+  if (isaUndefValue(Val))  // ee(undef, x) - undef
+return UndefValue::get(castPackedType(Val-getType())-getElementType());
+  
   if (const ConstantPacked *CVal = dyn_castConstantPacked(Val)) {
 if (const ConstantUInt *CIdx = dyn_castConstantUInt(Idx)) {
   return const_castConstant*(CVal-getOperand(CIdx-getValue()));
+} else if (isaUndefValue(Idx)) {
+  // ee({w,x,y,z}, undef) - w (an arbitrary value).
+  return const_castConstant*(CVal-getOperand(0));
 }
-  } 
+  }
   return 0;
 }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp ConstantFolding.h Constants.cpp Instruction.cpp Instructions.cpp Verifier.cpp

2006-01-17 Thread Robert L. Bocchino Jr.


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.82 - 1.83
ConstantFolding.h updated: 1.46 - 1.47
Constants.cpp updated: 1.144 - 1.145
Instruction.cpp updated: 1.49 - 1.50
Instructions.cpp updated: 1.30 - 1.31
Verifier.cpp updated: 1.143 - 1.144
---
Log message:

VMCore support for the insertelement operation.



---
Diffs of the changes:  (+147 -9)

 ConstantFolding.cpp |   57 
 ConstantFolding.h   |3 ++
 Constants.cpp   |   49 +---
 Instruction.cpp |1 
 Instructions.cpp|   25 --
 Verifier.cpp|   21 +++
 6 files changed, 147 insertions(+), 9 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.82 
llvm/lib/VMCore/ConstantFolding.cpp:1.83
--- llvm/lib/VMCore/ConstantFolding.cpp:1.82Tue Jan 10 14:03:46 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Jan 17 14:07:22 2006
@@ -734,6 +734,63 @@
   return 0;
 }
 
+Constant *llvm::ConstantFoldInsertElementInstruction(const Constant *Val,
+ const Constant *Elt,
+ const Constant *Idx) {
+  const ConstantUInt *CIdx = dyn_castConstantUInt(Idx);
+  if (!CIdx) return 0;
+  unsigned idxVal = CIdx-getValue();
+  if (const UndefValue *UVal = dyn_castUndefValue(Val)) {
+// Insertion of scalar constant into packed undef
+// Optimize away insertion of undef
+if (isaUndefValue(Elt))
+  return const_castConstant*(Val);
+// Otherwise break the aggregate undef into multiple undefs and do
+// the insertion
+unsigned numOps = 
+  castPackedType(Val-getType())-getNumElements();
+std::vectorConstant* Ops; 
+Ops.reserve(numOps);
+for (unsigned i = 0; i  numOps; ++i) {
+  const Constant *Op =
+(i == idxVal) ? Elt : UndefValue::get(Elt-getType());
+  Ops.push_back(const_castConstant*(Op));
+}
+return ConstantPacked::get(Ops);
+  }
+  if (const ConstantAggregateZero *CVal =
+  dyn_castConstantAggregateZero(Val)) {
+// Insertion of scalar constant into packed aggregate zero
+// Optimize away insertion of zero
+if (Elt-isNullValue())
+  return const_castConstant*(Val);
+// Otherwise break the aggregate zero into multiple zeros and do
+// the insertion
+unsigned numOps = 
+  castPackedType(Val-getType())-getNumElements();
+std::vectorConstant* Ops; 
+Ops.reserve(numOps);
+for (unsigned i = 0; i  numOps; ++i) {
+  const Constant *Op =
+(i == idxVal) ? Elt : Constant::getNullValue(Elt-getType());
+  Ops.push_back(const_castConstant*(Op));
+}
+return ConstantPacked::get(Ops);
+  }
+  if (const ConstantPacked *CVal = dyn_castConstantPacked(Val)) {
+// Insertion of scalar constant into packed constant
+std::vectorConstant* Ops; 
+Ops.reserve(CVal-getNumOperands());
+for (unsigned i = 0; i  CVal-getNumOperands(); ++i) {
+  const Constant *Op =
+(i == idxVal) ? Elt : castConstant(CVal-getOperand(i));
+  Ops.push_back(const_castConstant*(Op));
+}
+return ConstantPacked::get(Ops);
+  }
+  return 0;
+}
+
 /// isZeroSizedType - This type is zero sized if its an array or structure of
 /// zero sized types.  The only leaf zero sized type is an empty structure.
 static bool isMaybeZeroSizedType(const Type *Ty) {


Index: llvm/lib/VMCore/ConstantFolding.h
diff -u llvm/lib/VMCore/ConstantFolding.h:1.46 
llvm/lib/VMCore/ConstantFolding.h:1.47
--- llvm/lib/VMCore/ConstantFolding.h:1.46  Tue Jan 10 14:03:46 2006
+++ llvm/lib/VMCore/ConstantFolding.h   Tue Jan 17 14:07:22 2006
@@ -33,6 +33,9 @@
   const Constant *V2);
   Constant *ConstantFoldExtractElementInstruction(const Constant *Val,
   const Constant *Idx);
+  Constant *ConstantFoldInsertElementInstruction(const Constant *Val,
+ const Constant *Elt,
+ const Constant *Idx);
   Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
   const Constant *V2);
   Constant *ConstantFoldGetElementPtr(const Constant *C,


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.144 llvm/lib/VMCore/Constants.cpp:1.145
--- llvm/lib/VMCore/Constants.cpp:1.144 Tue Jan 10 14:03:46 2006
+++ llvm/lib/VMCore/Constants.cpp   Tue Jan 17 14:07:22 2006
@@ -347,8 +347,9 @@
   }
 };
 
-/// ExtractElementConstantExpr - This class is private to Constants.cpp, and 
is used
-/// behind the scenes to implement extractelement constant exprs.
+/// ExtractElementConstantExpr - This class is private to
+/// Constants.cpp, and is used behind the scenes to implement
+/// extractelement constant exprs.
 class 

[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp ConstantFolding.h Constants.cpp

2006-01-10 Thread Robert L. Bocchino Jr.


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.81 - 1.82
ConstantFolding.h updated: 1.45 - 1.46
Constants.cpp updated: 1.143 - 1.144
---
Log message:

Added constant folding support for the extractelement operation.


---
Diffs of the changes:  (+14 -0)

 ConstantFolding.cpp |   10 ++
 ConstantFolding.h   |2 ++
 Constants.cpp   |2 ++
 3 files changed, 14 insertions(+)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.81 
llvm/lib/VMCore/ConstantFolding.cpp:1.82
--- llvm/lib/VMCore/ConstantFolding.cpp:1.81Thu Jan  5 01:49:30 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Jan 10 14:03:46 2006
@@ -724,6 +724,16 @@
   return 0;
 }
 
+Constant *llvm::ConstantFoldExtractElementInstruction(const Constant *Val,
+  const Constant *Idx) {
+  if (const ConstantPacked *CVal = dyn_castConstantPacked(Val)) {
+if (const ConstantUInt *CIdx = dyn_castConstantUInt(Idx)) {
+  return const_castConstant*(CVal-getOperand(CIdx-getValue()));
+}
+  } 
+  return 0;
+}
+
 /// isZeroSizedType - This type is zero sized if its an array or structure of
 /// zero sized types.  The only leaf zero sized type is an empty structure.
 static bool isMaybeZeroSizedType(const Type *Ty) {


Index: llvm/lib/VMCore/ConstantFolding.h
diff -u llvm/lib/VMCore/ConstantFolding.h:1.45 
llvm/lib/VMCore/ConstantFolding.h:1.46
--- llvm/lib/VMCore/ConstantFolding.h:1.45  Thu Apr 21 18:46:51 2005
+++ llvm/lib/VMCore/ConstantFolding.h   Tue Jan 10 14:03:46 2006
@@ -31,6 +31,8 @@
   Constant *ConstantFoldSelectInstruction(const Constant *Cond,
   const Constant *V1,
   const Constant *V2);
+  Constant *ConstantFoldExtractElementInstruction(const Constant *Val,
+  const Constant *Idx);
   Constant *ConstantFoldBinaryInstruction(unsigned Opcode, const Constant *V1,
   const Constant *V2);
   Constant *ConstantFoldGetElementPtr(const Constant *C,


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.143 llvm/lib/VMCore/Constants.cpp:1.144
--- llvm/lib/VMCore/Constants.cpp:1.143 Tue Jan 10 13:05:24 2006
+++ llvm/lib/VMCore/Constants.cpp   Tue Jan 10 14:03:46 2006
@@ -1403,6 +1403,8 @@
 
 Constant *ConstantExpr::getExtractElementTy(const Type *ReqTy, Constant *Val,
 Constant *Idx) {
+  if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx))
+return FC;  // Fold a few common cases...
   // Look up the constant in the table first to ensure uniqueness
   std::vectorConstant* ArgVec(1, Val);
   ArgVec.push_back(Idx);



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-01-04 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.79 - 1.80
---
Log message:

fix some formatting problems


---
Diffs of the changes:  (+7 -7)

 ConstantFolding.cpp |   14 +++---
 1 files changed, 7 insertions(+), 7 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.79 
llvm/lib/VMCore/ConstantFolding.cpp:1.80
--- llvm/lib/VMCore/ConstantFolding.cpp:1.79Tue Jan  3 20:20:54 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Jan  5 01:19:51 2006
@@ -235,7 +235,7 @@
 //
 struct BoolRules : public TemplateRulesConstantBool, BoolRules {
 
-  static Constant *LessThan(const ConstantBool *V1, const ConstantBool *V2){
+  static Constant *LessThan(const ConstantBool *V1, const ConstantBool *V2) {
 return ConstantBool::get(V1-getValue()  V2-getValue());
   }
 
@@ -800,13 +800,13 @@
 if (SwappedRelation != Instruction::BinaryOpsEnd)
   return SetCondInst::getSwappedCondition(SwappedRelation);
 
-  } else if (const GlobalValue *CPR1 = dyn_castGlobalValue(V1)){
+  } else if (const GlobalValue *CPR1 = dyn_castGlobalValue(V1)) {
 if (isaConstantExpr(V2)) {  // Swap as necessary.
-Instruction::BinaryOps SwappedRelation = evaluateRelation(V2, V1);
-if (SwappedRelation != Instruction::BinaryOpsEnd)
-  return SetCondInst::getSwappedCondition(SwappedRelation);
-else
-  return Instruction::BinaryOpsEnd;
+  Instruction::BinaryOps SwappedRelation = evaluateRelation(V2, V1);
+  if (SwappedRelation != Instruction::BinaryOpsEnd)
+return SetCondInst::getSwappedCondition(SwappedRelation);
+  else
+return Instruction::BinaryOpsEnd;
 }
 
 // Now we know that the RHS is a GlobalValue or simple constant,



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-01-04 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.80 - 1.81
---
Log message:

Implement a few symbolic constant folding things.  X ? Y : Y is Y.

Fold:
seteq ({ short }* cast (int 1 to { short }*), { short }* null)
setlt ({ short }* cast (int 1 to { short }*), { short }* cast (int 2 to { short 
}*))

to false/true.  These last two commonly occur in the output of compilers that
tag integers, like cozmic's scheme compiler.

Tested by Regression/Assembler/ConstantExprFold.llx



---
Diffs of the changes:  (+32 -7)

 ConstantFolding.cpp |   39 ---
 1 files changed, 32 insertions(+), 7 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.80 
llvm/lib/VMCore/ConstantFolding.cpp:1.81
--- llvm/lib/VMCore/ConstantFolding.cpp:1.80Thu Jan  5 01:19:51 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Thu Jan  5 01:49:30 2006
@@ -720,6 +720,7 @@
   if (isaUndefValue(V1)) return const_castConstant*(V2);
   if (isaUndefValue(V2)) return const_castConstant*(V1);
   if (isaUndefValue(Cond)) return const_castConstant*(V1);
+  if (V1 == V2) return const_castConstant*(V1);
   return 0;
 }
 
@@ -786,16 +787,27 @@
 /// constants (like ConstantInt) to be the simplest, followed by
 /// GlobalValues, followed by ConstantExpr's (the most complex).
 ///
-static Instruction::BinaryOps evaluateRelation(const Constant *V1,
-   const Constant *V2) {
+static Instruction::BinaryOps evaluateRelation(Constant *V1, Constant *V2) {
   assert(V1-getType() == V2-getType() 
  Cannot compare different types of values!);
   if (V1 == V2) return Instruction::SetEQ;
 
   if (!isaConstantExpr(V1)  !isaGlobalValue(V1)) {
+if (!isaGlobalValue(V2)  !isaConstantExpr(V2)) {
+  // We distilled this down to a simple case, use the standard constant
+  // folder.
+  ConstantBool *R = dyn_castConstantBool(ConstantExpr::getSetEQ(V1, V2));
+  if (R == ConstantBool::True) return Instruction::SetEQ;
+  R = dyn_castConstantBool(ConstantExpr::getSetLT(V1, V2));
+  if (R == ConstantBool::True) return Instruction::SetLT;
+  R = dyn_castConstantBool(ConstantExpr::getSetGT(V1, V2));
+  if (R == ConstantBool::True) return Instruction::SetGT;
+  
+  // If we couldn't figure it out, bail.
+  return Instruction::BinaryOpsEnd;
+}
+
 // If the first operand is simple, swap operands.
-assert((isaGlobalValue(V2) || isaConstantExpr(V2)) 
-   Simple cases should have been handled by caller!);
 Instruction::BinaryOps SwappedRelation = evaluateRelation(V2, V1);
 if (SwappedRelation != Instruction::BinaryOpsEnd)
   return SetCondInst::getSwappedCondition(SwappedRelation);
@@ -826,7 +838,7 @@
   } else {
 // Ok, the LHS is known to be a constantexpr.  The RHS can be any of a
 // constantexpr, a CPR, or a simple constant.
-const ConstantExpr *CE1 = castConstantExpr(V1);
+ConstantExpr *CE1 = castConstantExpr(V1);
 Constant *CE1Op0 = CE1-getOperand(0);
 
 switch (CE1-getOpcode()) {
@@ -834,9 +846,21 @@
   // If the cast is not actually changing bits, and the second operand is a
   // null pointer, do the comparison with the pre-casted value.
   if (V2-isNullValue() 
-  CE1-getType()-isLosslesslyConvertibleTo(CE1Op0-getType()))
+  (isaPointerType(CE1-getType()) || CE1-getType()-isIntegral()))
 return evaluateRelation(CE1Op0,
 Constant::getNullValue(CE1Op0-getType()));
+
+  // If the dest type is a pointer type, and the RHS is a constantexpr cast
+  // from the same type as the src of the LHS, evaluate the inputs.  This 
is
+  // important for things like seteq (cast 4 to int*), (cast 5 to int*),
+  // which happens a lot in compilers with tagged integers.
+  if (ConstantExpr *CE2 = dyn_castConstantExpr(V2))
+if (isaPointerType(CE1-getType())  
+CE2-getOpcode() == Instruction::Cast 
+CE1-getOperand(0)-getType() == CE2-getOperand(0)-getType() 
+CE1-getOperand(0)-getType()-isIntegral()) {
+  return evaluateRelation(CE1-getOperand(0), CE2-getOperand(0));
+}
   break;
 
 case Instruction::GetElementPtr:
@@ -977,7 +1001,8 @@
   if (SetCondInst::isRelational(Opcode)) {
 if (isaUndefValue(V1) || isaUndefValue(V2))
   return UndefValue::get(Type::BoolTy);
-switch (evaluateRelation(V1, V2)) {
+switch (evaluateRelation(const_castConstant*(V1),
+ const_castConstant*(V2))) {
 default: assert(0  Unknown relational!);
 case Instruction::BinaryOpsEnd:
   break;  // Couldn't determine anything about these constants.



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

2006-01-03 Thread Chris Lattner


Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.78 - 1.79
---
Log message:

implement constant folding of ==/!= on constant packed, simplify some code.


---
Diffs of the changes:  (+11 -3)

 ConstantFolding.cpp |   14 +++---
 1 files changed, 11 insertions(+), 3 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.78 
llvm/lib/VMCore/ConstantFolding.cpp:1.79
--- llvm/lib/VMCore/ConstantFolding.cpp:1.78Tue Jan  3 20:15:02 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp Tue Jan  3 20:20:54 2006
@@ -385,6 +385,14 @@
 return 0;
   }
   static Constant *EqualTo(const ConstantPacked *V1, const ConstantPacked *V2) 
{
+for (unsigned i = 0, e = V1-getNumOperands(); i != e; ++i) {
+  Constant *C = 
+ConstantExpr::getSetEQ(const_castConstant*(V1-getOperand(i)),
+   const_castConstant*(V2-getOperand(i)));
+  if (ConstantBool *CB = dyn_castConstantBool(C))
+return CB;
+}
+// Otherwise, could not decide from any element pairs.
 return 0;
   }
 };
@@ -951,15 +959,15 @@
   case Instruction::SetGT:   C = ConstRules::get(V1, V2).lessthan(V2, 
V1);break;
   case Instruction::SetNE:   // V1 != V2  ===  !(V1 == V2)
 C = ConstRules::get(V1, V2).equalto(V1, V2);
-if (C) return ConstantExpr::get(Instruction::Xor, C, ConstantBool::True);
+if (C) return ConstantExpr::getNot(C);
 break;
   case Instruction::SetLE:   // V1 = V2  ===  !(V2  V1)
 C = ConstRules::get(V1, V2).lessthan(V2, V1);
-if (C) return ConstantExpr::get(Instruction::Xor, C, ConstantBool::True);
+if (C) return ConstantExpr::getNot(C);
 break;
   case Instruction::SetGE:   // V1 = V2  ===  !(V1  V2)
 C = ConstRules::get(V1, V2).lessthan(V1, V2);
-if (C) return ConstantExpr::get(Instruction::Xor, C, ConstantBool::True);
+if (C) return ConstantExpr::getNot(C);
 break;
   }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits