<div dir="ltr">I got it. Thanks, Nick. So, it is back to the previous problem. If I have the following instruction:<div><br></div><div><div style="font-size:12.8000001907349px">%3 = fadd double %1, double %2 </div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">I want to change it into </div><div style="font-size:12.8000001907349px">%6 = fadd <2 x double> %4, double %5 </div></div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">where %4 = <double %1, double %1>, %5 = <double %2, double %2>, how can I do this?</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Thanks,</div><div style="font-size:12.8000001907349px">Best</div><div style><span style="font-size:12.8000001907349px"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 1:56 AM, 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">zhi chen wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
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 use it<br>
to create the scalar version FADD. I want to have an instruction like:<br></span>
*%2 = fadd <2 x double> undef, <2 x double> undef. *The following is the<span class=""><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, 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 print it,<br>
I'll get:<br>
dupInst <2 x double> <double fadd (double undef, double undef), 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>
</span></blockquote>
<br>
IRBuilder gave you back a constant instead of an Instruction. This is why it returns a Value*. For a simple example, if you ask it to create "add i32 1, 2" it will not return an add instruction, it will instead return "i32 3" which is a ConstantInt.<br>
<br>
In your case, it returned to you a ConstantExpr whose getOpcode() shows Instruction::FAdd, and getOperand(0) and getOperand(1) show 'undef', but it is not an instruction. "Undef" is treated as a constant, so an fadd between two constants gets you a constant instead of an instruction.<br>
<br>
Usually it won't matter, just build the function top down and don't look at whether you're getting an Instruction* or Constant* and everything will be fine.<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>
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></span><span class="">
<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 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 <<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>>> 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 <<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>>> wrote:<br>
<br>
But IRBuilder.CreateXYZ only returns a "VALUE" 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 <<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>>> wrote:<br>
<br>
Yes. That's what I was the solution in my mind. But I<br>
just wanted to know if there was a generic way 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><br></span><span class="">
<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 blindly<br>
replacing<br>
instructions with vector equivalents is only going<br>
to work in a few<br>
cases anyway. You're probably best to 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></span>
<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> <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>
</span></blockquote>
<br>
</blockquote></div><br></div>