First attempt at handling frame index elimination.
[oota-llvm.git] / lib / VMCore / ConstantFold.cpp
index 5f7e0ef1b81ed8e409f8a71fbcdbf1dcf8ac5aa3..1fee5012b45611db4a3e73ae16edda25f308cb61 100644 (file)
@@ -582,6 +582,17 @@ Constant *llvm::ConstantFoldCastInstruction(const Constant *V,
   }
 }
 
+Constant *llvm::ConstantFoldSelectInstruction(const Constant *Cond,
+                                              const Constant *V1,
+                                              const Constant *V2) {
+  if (Cond == ConstantBool::True)
+    return const_cast<Constant*>(V1);
+  else if (Cond == ConstantBool::False)
+    return const_cast<Constant*>(V2);
+  return 0;
+}
+
+
 /// IdxCompare - Compare the two constants as though they were getelementptr
 /// indices.  This allows coersion of the types to be the same thing.
 ///
@@ -597,10 +608,10 @@ static int IdxCompare(Constant *C1, Constant *C2) {
   if (!isa<ConstantInt>(C1) || !isa<ConstantInt>(C2))
     return -2; // don't know!
   
-  // Ok, we have two differing integer indices.  Convert them to
-  // be the same type.  Long is always big enough, so we use it.
-  C1 = ConstantExpr::getCast(C1, Type::LongTy);
-  C2 = ConstantExpr::getCast(C2, Type::LongTy);
+  // Ok, we have two differing integer indices.  Sign extend them to be the same
+  // type.  Long is always big enough, so we use it.
+  C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
+  C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
   if (C1 == C2) return 0;  // Are they just differing types?
 
   // If they are really different, now that they are the same type, then we