zhi chen wrote:
Thanks Nick, that's something what I am trying to implement as the
following. But it seems I still only get the constant value not the
instruction. Could you please go over the following instruction and see
what wrong with it? Thanks for your time again.
Value *vecVal = NULL;
IRBuilder<> builder(&*pInst);
Type *vecTy = VectorType::get(Type::getDoubleTy(ctxt), 2);
Value *emptyVec = UndefValue::get(vecTy);
Type* u32Ty = Type::getInt32Ty(currF->getContext());
Value *index0 = ConstantInt::get(u32Ty, 0);
Value *index1 = ConstantInt::get(u32Ty, 1);
Instruction *InsertVal = InsertElementInst::Create(emptyVec, oprnd,
index0, "insert");
This makes you:
%insert = insertelement <2 x double> undef, double %oprnd, i32 0
So far so good.
InsertVal = InsertElementInst::Create(emptyVec, oprnd, index1,
"insert");
This makes you:
%insert1 = insertelement <2 x double> undef, double %oprnd, i32 1
Not what you wanted. You meant to create:
%insert1 = insertelement <2 x double> %insert, double %oprnd, i32 1
by calling
InsertVal = InsertElementInst::Create(InsertVal, oprnd, index1, "insert");
vecVal = builder.CreateFAdd(emptyVec, emptyVec, "");
This makes you:
%0 = fadd <2 x double> undef, undef
which constant folds away into a non-instruction. You wanted to sum
vecVal = builder.CreateFAdd(InsertVal, [...], "");
where the [...] is because you haven't yet written the code to create the second vector (%5) yet.
Nick