[llvm] r255157 - IR: Make ConstantDataArray::getFP actually return a ConstantDataArray

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 9 13:21:07 PST 2015


Author: bogner
Date: Wed Dec  9 15:21:07 2015
New Revision: 255157

URL: http://llvm.org/viewvc/llvm-project?rev=255157&view=rev
Log:
IR: Make ConstantDataArray::getFP actually return a ConstantDataArray

The ConstantDataArray::getFP(LLVMContext &, ArrayRef<uint16_t>)
overload has had a typo in it since it was written, where it will
create a Vector instead of an Array. This obviously doesn't work at
all, but it turns out that until r254991 there weren't actually any
callers of this overload. Fix the typo and add some test coverage.

Modified:
    llvm/trunk/lib/IR/Constants.cpp
    llvm/trunk/test/Transforms/ConstProp/insertvalue.ll
    llvm/trunk/unittests/IR/ConstantsTest.cpp

Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=255157&r1=255156&r2=255157&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Wed Dec  9 15:21:07 2015
@@ -2523,7 +2523,7 @@ Constant *ConstantDataArray::get(LLVMCon
 /// object.
 Constant *ConstantDataArray::getFP(LLVMContext &Context,
                                    ArrayRef<uint16_t> Elts) {
-  Type *Ty = VectorType::get(Type::getHalfTy(Context), Elts.size());
+  Type *Ty = ArrayType::get(Type::getHalfTy(Context), Elts.size());
   const char *Data = reinterpret_cast<const char *>(Elts.data());
   return getImpl(StringRef(const_cast<char *>(Data), Elts.size() * 2), Ty);
 }

Modified: llvm/trunk/test/Transforms/ConstProp/insertvalue.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/insertvalue.ll?rev=255157&r1=255156&r2=255157&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/insertvalue.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/insertvalue.ll Wed Dec  9 15:21:07 2015
@@ -74,3 +74,13 @@ define i32 @test-float-Nan() {
 ; CHECK: @test-float-Nan
 ; CHECK: ret i32 2139171423
 }
+
+define i16 @test-half-Nan() {
+  %A = bitcast i16 32256 to half
+  %B = insertvalue [1 x half] undef, half %A, 0
+  %C = extractvalue [1 x half] %B, 0
+  %D = bitcast half %C to i16
+  ret i16 %D
+; CHECK: @test-half-Nan
+; CHECK: ret i16 32256
+}

Modified: llvm/trunk/unittests/IR/ConstantsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/ConstantsTest.cpp?rev=255157&r1=255156&r2=255157&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/ConstantsTest.cpp (original)
+++ llvm/trunk/unittests/IR/ConstantsTest.cpp Wed Dec  9 15:21:07 2015
@@ -389,6 +389,29 @@ static std::string getNameOfType(Type *T
   return S;
 }
 
+TEST(ConstantsTest, BuildConstantDataArrays) {
+  LLVMContext Context;
+  std::unique_ptr<Module> M(new Module("MyModule", Context));
+
+  for (Type *T : {Type::getInt8Ty(Context), Type::getInt16Ty(Context),
+                  Type::getInt32Ty(Context), Type::getInt64Ty(Context)}) {
+    ArrayType *ArrayTy = ArrayType::get(T, 2);
+    Constant *Vals[] = {ConstantInt::get(T, 0), ConstantInt::get(T, 1)};
+    Constant *CDV = ConstantArray::get(ArrayTy, Vals);
+    ASSERT_TRUE(dyn_cast<ConstantDataArray>(CDV) != nullptr)
+        << " T = " << getNameOfType(T);
+  }
+
+  for (Type *T : {Type::getHalfTy(Context), Type::getFloatTy(Context),
+                  Type::getDoubleTy(Context)}) {
+    ArrayType *ArrayTy = ArrayType::get(T, 2);
+    Constant *Vals[] = {ConstantFP::get(T, 0), ConstantFP::get(T, 1)};
+    Constant *CDV = ConstantArray::get(ArrayTy, Vals);
+    ASSERT_TRUE(dyn_cast<ConstantDataArray>(CDV) != nullptr)
+        << " T = " << getNameOfType(T);
+  }
+}
+
 TEST(ConstantsTest, BuildConstantDataVectors) {
   LLVMContext Context;
   std::unique_ptr<Module> M(new Module("MyModule", Context));




More information about the llvm-commits mailing list