<div dir="ltr"><div>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. </div><div><br></div><div> Value *vecVal = NULL;</div><div> IRBuilder<> builder(&*pInst);</div><div> Type *vecTy = VectorType::get(Type::getDoubleTy(ctxt), 2);</div><div> Value *emptyVec = UndefValue::get(vecTy);</div><div> Type* u32Ty = Type::getInt32Ty(currF->getContext());</div><div> Value *index0 = ConstantInt::get(u32Ty, 0);</div><div> Value *index1 = ConstantInt::get(u32Ty, 1);</div><div><br></div><div> Instruction *InsertVal = InsertElementInst::Create(emptyVec, oprnd, index0, "insert");</div><div> InsertVal = InsertElementInst::Create(emptyVec, oprnd, index1, "insert");</div><div><br></div><div> vecVal = builder.CreateFAdd(emptyVec, emptyVec, "");<br></div><div><br></div><div>Best,</div><div>Zhi</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 12:17 PM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">zhi chen wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I got it. Thanks, Nick. So, it is back to the previous problem. If I<br>
have the following instruction:<br>
<br>
%3 = fadd double %1, double %2<br>
<br>
I want to change it into<br>
%6 = fadd <2 x double> %4, double %5<br>
<br>
where %4 = <double %1, double %1>, %5 = <double %2, double %2>, how can<br>
I do this?<br>
</blockquote>
<br></span>
%4 = <double %1, double %1> isn't valid syntax, the way you would do it is:<br>
<br>
%tmp4 = insertelement <2 x double> undef, double %1, i32 0<br>
%4 = insertelement <2 x double> %A, double %1, i32 1<br>
<br>
and similarly for %5, then you create the fadd of the two of them.<br>
<br>
Nick<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
Thanks,<br>
Best<br>
<br>
<br>
On Fri, Apr 17, 2015 at 1:56 AM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a><br></span><div><div class="h5">
<mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>> wrote:<br>
<br>
zhi chen wrote:<br>
<br>
It seems that the problem was because I used builder.CreateFAdd to<br>
create a <2 x double> vectortype FADD instruction. It works if I<br>
use it<br>
to create the scalar version FADD. I want to have an instruction<br>
like:<br>
*%2 = fadd <2 x double> undef, <2 x double> undef. *The<br>
following is the<br>
way I used to create the vectorized FADD instruction:<br>
<br>
//pInst is a double type instruction<br>
<br>
Type *vecTy = VectorType::get(pInst->getType(), 2);<br>
Value *emptyVec = UndefValue::get(vecTy);<br>
IRBuilder<> builder(&*pInst);<br>
Value *dupVal = builder.CreateFAdd(emptyVec, emptyVec,<br>
instName);<br>
std::cout << " dupVal " << *dupVal << "\n";<br>
<br>
It outputs: dupVal <2 x double> <double fadd (double undef, double<br>
undef), double fadd (double undef, double undef)><br>
<br>
If I dyn_cast the dupVal to instruction type (dupInst) and print<br>
dupInst, it outputs: "dupInst printing a <null> value"<br>
But if I use Instruction *dupInst = (Instruction *) dupVal and<br>
print it,<br>
I'll get:<br>
dupInst <2 x double> <double fadd (double undef, double undef),<br>
double<br>
fadd (double undef, double undef)><br>
<br>
It seems that if simply fails to generate the vectorized FADD<br>
instruction. Anything wrong with my code?<br>
<br>
<br>
IRBuilder gave you back a constant instead of an Instruction. This<br>
is why it returns a Value*. For a simple example, if you ask it to<br>
create "add i32 1, 2" it will not return an add instruction, it will<br>
instead return "i32 3" which is a ConstantInt.<br>
<br>
In your case, it returned to you a ConstantExpr whose getOpcode()<br>
shows Instruction::FAdd, and getOperand(0) and getOperand(1) show<br>
'undef', but it is not an instruction. "Undef" is treated as a<br>
constant, so an fadd between two constants gets you a constant<br>
instead of an instruction.<br>
<br>
Usually it won't matter, just build the function top down and don't<br>
look at whether you're getting an Instruction* or Constant* and<br>
everything will be fine.<br>
<br>
Nick<br>
<br>
<br>
Best,<br>
Zhi<br>
<br>
<br>
<br>
<br>
<br>
On Thu, Apr 16, 2015 at 11:55 PM, zhi chen <<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a><br>
<mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>><br></div></div><span class="">
<mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a> <mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>>>> wrote:<br>
<br>
Yes. I was using this. It seems the produced instruction is not<br>
correct. There are probably some other problems. I need to<br>
recheck<br>
it. Thanks for your help, Daniel.<br>
<br>
Best,<br>
Zhi<br>
<br>
On Thu, Apr 16, 2015 at 11:40 PM, Daniel Berlin<br>
<<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a> <mailto:<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>><br></span><span class="">
<mailto:<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a> <mailto:<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>>>> wrote:<br>
<br>
Value * is the instruction.<br>
<br>
use dyn_cast<Instruction> to get to it.<br>
<br>
<br>
On Thu, Apr 16, 2015 at 11:39 PM zhi chen<br>
<<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a> <mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>><br></span><span class="">
<mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a> <mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>>>> wrote:<br>
<br>
But IRBuilder.CreateXYZ only returns a "VALUE"<br>
type. Can I<br>
get the instruction created by it? For example,<br>
<br>
IRBuilder<> builder(&*pinst);<br>
Value *val = builder.CreateFAdd(LV, RV, "");<br>
<br>
How can I get the fadd instruction created by builder?<br>
<br>
On Thu, Apr 16, 2015 at 8:52 PM, zhi chen<br>
<<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a> <mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>><br></span><span class="">
<mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a> <mailto:<a href="mailto:zchenhn@gmail.com" target="_blank">zchenhn@gmail.com</a>>>> wrote:<br>
<br>
Yes. That's what I was the solution in my mind.<br>
But I<br>
just wanted to know if there was a generic way<br>
to save<br>
some code...<br>
<br>
On Thu, Apr 16, 2015 at 8:32 PM, Tim Northover<br>
<<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a> <mailto:<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>><br></span>
<mailto:<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a><span class=""><br>
<mailto:<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>>>> wrote:<br>
<br>
> I understand that I can detect the operation<br>
first, and use "create" to<br>
> create for each of them. But I don't if there is a<br>
generic way to do this<br>
> because if might be add/sub/mul... operations.<br>
<br>
I don't think there is. Realistically, just<br>
blindly<br>
replacing<br>
instructions with vector equivalents is<br>
only going<br>
to work in a few<br>
cases anyway. You're probably best to<br>
intentionally<br>
detect those cases<br>
and call the correct CreateXYZ function.<br>
<br>
Cheers.<br>
<br>
Tim.<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>><br></span>
<mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>>><span class=""><br>
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <mailto:<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>><br>
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br>
<br>
<br>
</span></blockquote>
<br>
</blockquote></div><br></div>