make sure that we don't use a common symbol if a section was specified
[oota-llvm.git] / lib / Analysis / ConstantFolding.cpp
index 3321115c53e21bb9562156880c45ba42f2e9b6b8..359766d444f88bd9d7ba8e464630ed82c70cff93 100644 (file)
@@ -76,7 +76,8 @@ llvm::canConstantFoldCallTo(Function *F) {
     case 'p':
       return Name == "pow";
     case 's':
-      return Name == "sin" || Name == "sinh" || Name == "sqrt";
+      return Name == "sin" || Name == "sinh" || 
+             Name == "sqrt" || Name == "sqrtf";
     case 't':
       return Name == "tan" || Name == "tanh";
     default:
@@ -150,6 +151,8 @@ llvm::ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands) {
             return ConstantFP::get(Ty, sinh(V));
           else if (Name == "sqrt" && V >= 0)
             return ConstantFP::get(Ty, sqrt(V));
+          else if (Name == "sqrtf" && V >= 0)
+            return ConstantFP::get(Ty, sqrt((float)V));
           break;
         case 't':
           if (Name == "tan")
@@ -160,14 +163,15 @@ llvm::ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands) {
         default:
           break;
       }
-    } else if (ConstantUInt *Op = dyn_cast<ConstantUInt>(Operands[0])) {
-      uint64_t V = Op->getValue();
+    } else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
+      assert(Op->getType()->isUnsigned() && "bswap args must be unsigned");
+      uint64_t V = Op->getZExtValue();
       if (Name == "llvm.bswap.i16")
-        return ConstantUInt::get(Ty, ByteSwap_16(V));
+        return ConstantInt::get(Ty, ByteSwap_16(V));
       else if (Name == "llvm.bswap.i32")
-        return ConstantUInt::get(Ty, ByteSwap_32(V));
+        return ConstantInt::get(Ty, ByteSwap_32(V));
       else if (Name == "llvm.bswap.i64")
-        return ConstantUInt::get(Ty, ByteSwap_64(V));
+        return ConstantInt::get(Ty, ByteSwap_64(V));
     }
   } else if (Operands.size() == 2) {
     if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {