[llvm-commits] [llvm] r56233 - in /llvm/trunk: include/llvm/Bitcode/LLVMBitCodes.h lib/Bitcode/Reader/BitcodeReader.cpp lib/Bitcode/Writer/BitcodeWriter.cpp test/Assembler/vector-select.ll

Dan Gohman gohman at apple.com
Mon Sep 15 18:01:33 PDT 2008


Author: djg
Date: Mon Sep 15 20:01:33 2008
New Revision: 56233

URL: http://llvm.org/viewvc/llvm-project?rev=56233&view=rev
Log:
Re-enables the new vector select in the bitcode reader, by modifying the
bitcode reader/writer as follows:

- add and use new bitcode FUNC_CODE_INST_VSELECT to handle the llvm
select opcode using either i1 or [N x i1] as the selector.
- retain old BITCODE FUNC_CODE_INST_SELECT in the bitcode reader to
handle select on i1 for backwards compatibility with existing bitcode
files.
- re-enable the vector-select.ll test program.

Also, rename the recently added bitcode opcode FUNC_CODE_INST_VCMP to
FUNC_CODE_INST_CMP2 and make the bitcode writer use it to handle
fcmp/icmp on scalars or vectors. In the bitcode writer, use
FUNC_CODE_INST_CMP for vfcmp/vicmp only. In the bitcode reader, have
FUNC_CODE_INST_CMP handle icmp/fcmp returning bool, for backwards
compatibility with existing bitcode files.

Patch by Preston Gurd!

Modified:
    llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
    llvm/trunk/test/Assembler/vector-select.ll

Modified: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h?rev=56233&r1=56232&r2=56233&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h (original)
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h Mon Sep 15 20:01:33 2008
@@ -206,8 +206,10 @@
     FUNC_CODE_INST_GETRESULT   = 25, // GETRESULT:  [ty, opval, n]
     FUNC_CODE_INST_EXTRACTVAL  = 26, // EXTRACTVAL: [n x operands]
     FUNC_CODE_INST_INSERTVAL   = 27, // INSERTVAL:  [n x operands]
-    // fcmp/icmp returning vector of Int1Ty, NOT for vicmp/vfcmp
-    FUNC_CODE_INST_VCMP        = 28  // VCMP:       [opty, opval, opval, pred]
+    // fcmp/icmp returning Int1TY or vector of Int1Ty, NOT for vicmp/vfcmp
+    FUNC_CODE_INST_CMP2        = 28, // VCMP:       [opty, opval, opval, pred]
+    // new select on i1 or [N x i1]
+    FUNC_CODE_INST_VSELECT     = 29  // VSELECT:    [ty,opval,opval,predty,pred]
   };
 } // End bitc namespace
 } // End llvm namespace

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=56233&r1=56232&r2=56233&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Mon Sep 15 20:01:33 2008
@@ -1495,15 +1495,32 @@
     }
       
     case bitc::FUNC_CODE_INST_SELECT: { // SELECT: [opval, ty, opval, opval]
+      // obsolete form of select
+      // handles select i1 ... in old bitcode
       unsigned OpNum = 0;
       Value *TrueVal, *FalseVal, *Cond;
       if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
           getValue(Record, OpNum, TrueVal->getType(), FalseVal) ||
           getValue(Record, OpNum, Type::Int1Ty, Cond))
         return Error("Invalid SELECT record");
+      
+      I = SelectInst::Create(Cond, TrueVal, FalseVal);
+      break;
+    }
+      
+    case bitc::FUNC_CODE_INST_VSELECT: {// VSELECT: [ty,opval,opval,predty,pred]
+      // new form of select
+      // handles select i1 or select [N x i1]
+      unsigned OpNum = 0;
+      Value *TrueVal, *FalseVal, *Cond;
+      if (getValueTypePair(Record, OpNum, NextValueNo, TrueVal) ||
+          getValue(Record, OpNum, TrueVal->getType(), FalseVal) ||
+          getValueTypePair(Record, OpNum, NextValueNo, Cond))
+        return Error("Invalid SELECT record");
 
       // select condition can be either i1 or [N x i1]
-      if (const VectorType* vector_type = dyn_cast<const VectorType>(Cond->getType())) {
+      if (const VectorType* vector_type =
+          dyn_cast<const VectorType>(Cond->getType())) {
         // expect <n x i1>
         if (vector_type->getElementType() != Type::Int1Ty) 
           return Error("Invalid SELECT condition type");
@@ -1557,6 +1574,8 @@
     }
       
     case bitc::FUNC_CODE_INST_CMP: { // CMP: [opty, opval, opval, pred]
+      // VFCmp/VICmp
+      // or old form of ICmp/FCmp returning bool
       unsigned OpNum = 0;
       Value *LHS, *RHS;
       if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
@@ -1574,16 +1593,15 @@
         I = new VICmpInst((ICmpInst::Predicate)Record[OpNum], LHS, RHS);
       break;
     }
-    case bitc::FUNC_CODE_INST_VCMP: { // VCMP: [opty, opval, opval, pred]
-      // Fcmp/ICmp returning vector of bool
+    case bitc::FUNC_CODE_INST_CMP2: { // CMP2: [opty, opval, opval, pred]
+      // Fcmp/ICmp returning bool or vector of bool
       unsigned OpNum = 0;
       Value *LHS, *RHS;
       if (getValueTypePair(Record, OpNum, NextValueNo, LHS) ||
           getValue(Record, OpNum, LHS->getType(), RHS) ||
           OpNum+1 != Record.size())
-        return Error("Invalid VCMP record");
+        return Error("Invalid CMP2 record");
       
-      // will always be vector
       if (LHS->getType()->isFPOrFPVector())
         I = new FCmpInst((FCmpInst::Predicate)Record[OpNum], LHS, RHS);
       else 

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=56233&r1=56232&r2=56233&view=diff

==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Mon Sep 15 20:01:33 2008
@@ -746,10 +746,10 @@
     break;
   }
   case Instruction::Select:
-    Code = bitc::FUNC_CODE_INST_SELECT;
+    Code = bitc::FUNC_CODE_INST_VSELECT;
     PushValueAndType(I.getOperand(1), InstID, Vals, VE);
     Vals.push_back(VE.getValueID(I.getOperand(2)));
-    Vals.push_back(VE.getValueID(I.getOperand(0)));
+    PushValueAndType(I.getOperand(0), InstID, Vals, VE);
     break;
   case Instruction::ExtractElement:
     Code = bitc::FUNC_CODE_INST_EXTRACTELT;
@@ -772,11 +772,10 @@
   case Instruction::FCmp:
   case Instruction::VICmp:
   case Instruction::VFCmp:
-    if (isa<VectorType>(I.getOperand(0)->getType())
-        && (I.getOpcode() == Instruction::ICmp
-            || I.getOpcode() == Instruction::FCmp)) {
-      // compare returning vector of Int1Ty
-      Code = bitc::FUNC_CODE_INST_VCMP;
+    if (I.getOpcode() == Instruction::ICmp
+        || I.getOpcode() == Instruction::FCmp) {
+      // compare returning Int1Ty or vector of Int1Ty
+      Code = bitc::FUNC_CODE_INST_CMP2;
     } else {
       Code = bitc::FUNC_CODE_INST_CMP;
     }

Modified: llvm/trunk/test/Assembler/vector-select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/vector-select.ll?rev=56233&r1=56232&r2=56233&view=diff

==============================================================================
--- llvm/trunk/test/Assembler/vector-select.ll (original)
+++ llvm/trunk/test/Assembler/vector-select.ll Mon Sep 15 20:01:33 2008
@@ -1,5 +1,4 @@
 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep select
-; XFAIL: *
 ; rudimentary test of select on vectors returning vector of bool
 
 define <4 x i32> @foo(<4 x i32> %a, <4 x i32> %b,





More information about the llvm-commits mailing list