[llvm] r246459 - [BitcodeReader] Ensure we can read constant vector selects with an i1 condition

Filipe Cabecinhas via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 11:00:30 PDT 2015


Author: filcab
Date: Mon Aug 31 13:00:30 2015
New Revision: 246459

URL: http://llvm.org/viewvc/llvm-project?rev=246459&view=rev
Log:
[BitcodeReader] Ensure we can read constant vector selects with an i1 condition

Summary:
Constant vectors weren't allowed to have an i1 condition in the
BitcodeReader. Make sure we have the same restrictions that are
documented, not more.

Reviewers: nlewycky, rafael, kschimpf

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12440

Modified:
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/test/Bitcode/select.ll

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=246459&r1=246458&r2=246459&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Aug 31 13:00:30 2015
@@ -2475,11 +2475,12 @@ std::error_code BitcodeReader::parseCons
 
       Type *SelectorTy = Type::getInt1Ty(Context);
 
-      // If CurTy is a vector of length n, then Record[0] must be a <n x i1>
-      // vector. Otherwise, it must be a single bit.
+      // The selector might be an i1 or an <n x i1>
+      // Get the type from the ValueList before getting a forward ref.
       if (VectorType *VTy = dyn_cast<VectorType>(CurTy))
-        SelectorTy = VectorType::get(Type::getInt1Ty(Context),
-                                     VTy->getNumElements());
+        if (Value *V = ValueList[Record[0]])
+          if (SelectorTy != V->getType())
+            SelectorTy = VectorType::get(SelectorTy, VTy->getNumElements());
 
       V = ConstantExpr::getSelect(ValueList.getConstantFwdRef(Record[0],
                                                               SelectorTy),

Modified: llvm/trunk/test/Bitcode/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/select.ll?rev=246459&r1=246458&r2=246459&view=diff
==============================================================================
--- llvm/trunk/test/Bitcode/select.ll (original)
+++ llvm/trunk/test/Bitcode/select.ll Mon Aug 31 13:00:30 2015
@@ -8,3 +8,11 @@ define <2 x i32> @main() {
 ; CHECK: define <2 x i32> @main() {
 ; CHECK:   ret <2 x i32> <i32 0, i32 undef>
 ; CHECK: }
+
+define <2 x float> @f() {
+  ret <2 x float> select (i1 ptrtoint (<2 x float> ()* @f to i1), <2 x float> <float 1.000000e+00, float 0.000000e+00>, <2 x float> zeroinitializer)
+}
+
+; CHECK: define <2 x float> @f() {
+; CHECK:   ret <2 x float> select (i1 ptrtoint (<2 x float> ()* @f to i1), <2 x float> <float 1.000000e+00, float 0.000000e+00>, <2 x float> zeroinitializer)
+; CHECK: }




More information about the llvm-commits mailing list