[LLVMdev] double* to <2 x double>*

zhi chen
Thu, 16 Apr 2015 07:46:23 -0000

Does anyone know how to instrument *double* to <2 x doulbe>**, e.g., 2.2
--> <2.2, 2.2>?
For example, I want to change the following IR code

%arrayidx1 = getelementptr inbounds [100 x double]* @main.B, i32 0, i32
%i.021
%1 = load double* %arrayidx1, align 4, !tbaa !0

to:

%arrayidx1 = getelementptr inbounds [100 x double]* @main.B, i32 0, i32
%i.021
%1 = bitcast double* %arrayidx1 to <2 x double>*
%2 = load <2 x double>* %1, align 4

what I right now doing is:
*Assume pInst is *%1 = load double* %arrayidx1, align 4, !tbaa !0

Value *loadValue = pInst->getOperand(0);
Type *vecTy = VectorType::get(Type::getDoublePtrTy(currF->getContext()), 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, loadValue,
index0, "");
InsertVal = InsertElementInst::Create(emptyVec, loadValue, index1,
"");
InsertVal->insertBefore(pInst);

It turned out that the way I am doing is not right because the output is <2
x double*>. Any help will be appreciated!

BTW, can I use bitcastInst (*if so, how?*) or I have to use
insertelementInst?

Thanks,
Zhi
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150416/1e4dd80f/attachment.html>