Index: docs/LangRef.rst =================================================================== --- docs/LangRef.rst +++ docs/LangRef.rst @@ -4470,7 +4470,7 @@ :: - = extractelement > , i32 ; yields + = extractelement > , ; yields Overview: """"""""" @@ -4484,7 +4484,7 @@ The first operand of an '``extractelement``' instruction is a value of :ref:`vector ` type. The second operand is an index indicating the position from which to extract the element. The index may be a -variable. +variable of any integer type. Semantics: """""""""" @@ -4510,7 +4510,7 @@ :: - = insertelement > , , i32 ; yields > + = insertelement > , , ; yields > Overview: """"""""" @@ -4525,7 +4525,7 @@ :ref:`vector ` type. The second operand is a scalar value whose type must equal the element type of the first operand. The third operand is an index indicating the position at which to insert the value. The -index may be a variable. +index may be a variable of any integer type. Semantics: """""""""" Index: lib/Bitcode/Reader/BitcodeReader.cpp =================================================================== --- lib/Bitcode/Reader/BitcodeReader.cpp +++ lib/Bitcode/Reader/BitcodeReader.cpp @@ -1425,21 +1425,25 @@ dyn_cast_or_null(getTypeByID(Record[0])); if (!OpTy) return Error(InvalidRecord); + Type *IdxTy = getTypeByID(Record[2]); + if (!IdxTy || !IdxTy->isIntegerTy()) // FIXME: Remove with LLVM 4.0 + IdxTy = Type::getInt32Ty(Context); Constant *Op0 = ValueList.getConstantFwdRef(Record[1], OpTy); - Constant *Op1 = ValueList.getConstantFwdRef(Record[2], - Type::getInt32Ty(Context)); + Constant *Op1 = ValueList.getConstantFwdRef(Record[2], IdxTy); V = ConstantExpr::getExtractElement(Op0, Op1); break; } case bitc::CST_CODE_CE_INSERTELT: { // CE_INSERTELT: [opval, opval, opval] VectorType *OpTy = dyn_cast(CurTy); + Type *IdxTy = getTypeByID(Record[2]); + if (!IdxTy || !IdxTy->isIntegerTy()) // FIXME: Remove with LLVM 4.0 + IdxTy = Type::getInt32Ty(Context); if (Record.size() < 3 || !OpTy) return Error(InvalidRecord); Constant *Op0 = ValueList.getConstantFwdRef(Record[0], OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Record[1], OpTy->getElementType()); - Constant *Op2 = ValueList.getConstantFwdRef(Record[2], - Type::getInt32Ty(Context)); + Constant *Op2 = ValueList.getConstantFwdRef(Record[2], IdxTy); V = ConstantExpr::getInsertElement(Op0, Op1, Op2); break; } @@ -2460,7 +2464,7 @@ unsigned OpNum = 0; Value *Vec, *Idx; if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || - popValue(Record, OpNum, NextValueNo, Type::getInt32Ty(Context), Idx)) + getValueTypePair(Record, OpNum, NextValueNo, Idx)) return Error(InvalidRecord); I = ExtractElementInst::Create(Vec, Idx); InstructionList.push_back(I); @@ -2473,7 +2477,7 @@ if (getValueTypePair(Record, OpNum, NextValueNo, Vec) || popValue(Record, OpNum, NextValueNo, cast(Vec->getType())->getElementType(), Elt) || - popValue(Record, OpNum, NextValueNo, Type::getInt32Ty(Context), Idx)) + getValueTypePair(Record, OpNum, NextValueNo, Idx)) return Error(InvalidRecord); I = InsertElementInst::Create(Vec, Elt, Idx); InstructionList.push_back(I); Index: lib/Bitcode/Writer/BitcodeWriter.cpp =================================================================== --- lib/Bitcode/Writer/BitcodeWriter.cpp +++ lib/Bitcode/Writer/BitcodeWriter.cpp @@ -1253,13 +1253,13 @@ case Instruction::ExtractElement: Code = bitc::FUNC_CODE_INST_EXTRACTELT; PushValueAndType(I.getOperand(0), InstID, Vals, VE); - pushValue(I.getOperand(1), InstID, Vals, VE); + PushValueAndType(I.getOperand(1), InstID, Vals, VE); break; case Instruction::InsertElement: Code = bitc::FUNC_CODE_INST_INSERTELT; PushValueAndType(I.getOperand(0), InstID, Vals, VE); pushValue(I.getOperand(1), InstID, Vals, VE); - pushValue(I.getOperand(2), InstID, Vals, VE); + PushValueAndType(I.getOperand(2), InstID, Vals, VE); break; case Instruction::ShuffleVector: Code = bitc::FUNC_CODE_INST_SHUFFLEVEC; Index: lib/IR/Constants.cpp =================================================================== --- lib/IR/Constants.cpp +++ lib/IR/Constants.cpp @@ -1937,8 +1937,8 @@ Constant *ConstantExpr::getExtractElement(Constant *Val, Constant *Idx) { assert(Val->getType()->isVectorTy() && "Tried to create extractelement operation on non-vector type!"); - assert(Idx->getType()->isIntegerTy(32) && - "Extractelement index must be i32 type!"); + assert(Idx->getType()->isIntegerTy() && + "Extractelement index must be an integer type!"); if (Constant *FC = ConstantFoldExtractElementInstruction(Val, Idx)) return FC; // Fold a few common cases. @@ -1958,7 +1958,7 @@ "Tried to create insertelement operation on non-vector type!"); assert(Elt->getType() == Val->getType()->getVectorElementType() && "Insertelement types must match!"); - assert(Idx->getType()->isIntegerTy(32) && + assert(Idx->getType()->isIntegerTy() && "Insertelement index must be i32 type!"); if (Constant *FC = ConstantFoldInsertElementInstruction(Val, Elt, Idx)) Index: lib/IR/Instructions.cpp =================================================================== --- lib/IR/Instructions.cpp +++ lib/IR/Instructions.cpp @@ -1479,7 +1479,7 @@ bool ExtractElementInst::isValidOperands(const Value *Val, const Value *Index) { - if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy(32)) + if (!Val->getType()->isVectorTy() || !Index->getType()->isIntegerTy()) return false; return true; } @@ -1526,7 +1526,7 @@ if (Elt->getType() != cast(Vec->getType())->getElementType()) return false;// Second operand of insertelement must be vector element type. - if (!Index->getType()->isIntegerTy(32)) + if (!Index->getType()->isIntegerTy()) return false; // Third operand of insertelement must be i32. return true; } Index: test/CodeGen/X86/vec_splat.ll =================================================================== --- test/CodeGen/X86/vec_splat.ll +++ test/CodeGen/X86/vec_splat.ll @@ -38,15 +38,14 @@ define <4 x float> @load_extract_splat(<4 x float>* nocapture readonly %ptr, i64 %i, i64 %j) nounwind { %1 = getelementptr inbounds <4 x float>* %ptr, i64 %i %2 = load <4 x float>* %1, align 16 - %3 = trunc i64 %j to i32 - %4 = extractelement <4 x float> %2, i32 %3 - %5 = insertelement <4 x float> undef, float %4, i32 0 - %6 = insertelement <4 x float> %5, float %4, i32 1 - %7 = insertelement <4 x float> %6, float %4, i32 2 - %8 = insertelement <4 x float> %7, float %4, i32 3 - ret <4 x float> %8 + %3 = extractelement <4 x float> %2, i64 %j + %4 = insertelement <4 x float> undef, float %3, i32 0 + %5 = insertelement <4 x float> %4, float %3, i32 1 + %6 = insertelement <4 x float> %5, float %3, i32 2 + %7 = insertelement <4 x float> %6, float %3, i32 3 + ret <4 x float> %7 ; AVX-LABEL: load_extract_splat -; AVX-NOT: rsp +; AVX-NOT: mov ; AVX: vbroadcastss } Index: test/Feature/instructions.ll =================================================================== --- test/Feature/instructions.ll +++ test/Feature/instructions.ll @@ -4,11 +4,13 @@ define i32 @test_extractelement(<4 x i32> %V) { %R = extractelement <4 x i32> %V, i32 1 ; [#uses=1] + %S = extractelement <4 x i32> %V, i64 1 ; [#uses=0] ret i32 %R } define <4 x i32> @test_insertelement(<4 x i32> %V) { %R = insertelement <4 x i32> %V, i32 0, i32 0 ; <<4 x i32>> [#uses=1] + %S = insertelement <4 x i32> %V, i32 0, i64 0 ; <<4 x i32>> [#uses=0] ret <4 x i32> %R }