<div dir="ltr">Thank you Nick, that's was a stupid error. </div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 17, 2015 at 12:28 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">
Thanks Nick, that's something what I am trying to implement as the<br>
following. But it seems I still only get the constant value not the<br>
instruction. Could you please go over the following instruction and see<br>
what wrong with it? Thanks for your time again.<br>
<br>
Value *vecVal = NULL;<br>
IRBuilder<> builder(&*pInst);<br>
Type *vecTy = VectorType::get(Type::getDoubleTy(ctxt), 2);<br>
Value *emptyVec = UndefValue::get(vecTy);<br>
Type* u32Ty = Type::getInt32Ty(currF->getContext());<br>
Value *index0 = ConstantInt::get(u32Ty, 0);<br>
Value *index1 = ConstantInt::get(u32Ty, 1);<br>
<br>
Instruction *InsertVal = InsertElementInst::Create(emptyVec, oprnd,<br>
index0, "insert");<br>
</blockquote>
<br></span>
This makes you:<br>
<br>
%insert = insertelement <2 x double> undef, double %oprnd, i32 0<br>
<br>
So far so good.<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
InsertVal = InsertElementInst::Create(emptyVec, oprnd, index1,<br>
"insert");<br>
</blockquote>
<br></span>
This makes you:<br>
<br>
%insert1 = insertelement <2 x double> undef, double %oprnd, i32 1<br>
<br>
Not what you wanted. You meant to create:<br>
<br>
%insert1 = insertelement <2 x double> %insert, double %oprnd, i32 1<br>
<br>
by calling<br>
<br>
InsertVal = InsertElementInst::Create(InsertVal, oprnd, index1, "insert");<span class=""><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
vecVal = builder.CreateFAdd(emptyVec, emptyVec, "");<br>
</blockquote>
<br></span>
This makes you:<br>
<br>
%0 = fadd <2 x double> undef, undef<br>
<br>
which constant folds away into a non-instruction. You wanted to sum<br>
<br>
vecVal = builder.CreateFAdd(InsertVal, [...], "");<br>
<br>
where the [...] is because you haven't yet written the code to create the second vector (%5) yet.<span class="HOEnZb"><font color="#888888"><br>
<br>
Nick<br>
<br>
<br>
</font></span><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>
On Fri, Apr 17, 2015 at 12:17 PM, Nick Lewycky <<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a><br></span><span class="">
<mailto:<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>>> wrote:<br>
<br>
zhi chen wrote:<br>
<br>
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>,<br>
how can<br>
I do this?<br>
<br>
<br>
%4 = <double %1, double %1> isn't valid syntax, the way you would do<br>
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>
<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>
<mailto:<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> <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<br>
builder.CreateFAdd to<br>
create a <2 x double> vectortype FADD instruction. It<br>
works if I<br>
use it<br>
to create the scalar version FADD. I want to have an<br>
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<br>
undef, double<br>
undef), double fadd (double undef, double undef)><br>
<br>
If I dyn_cast the dupVal to instruction type (dupInst)<br>
and print<br>
dupInst, it outputs: "dupInst printing a <null> value"<br>
But if I use Instruction *dupInst = (Instruction *)<br>
dupVal and<br>
print it,<br>
I'll get:<br>
dupInst <2 x double> <double fadd (double undef, double<br>
undef),<br>
double<br>
fadd (double undef, double undef)><br>
<br>
It seems that if simply fails to generate the<br>
vectorized FADD<br>
instruction. Anything wrong with my code?<br>
<br>
<br>
IRBuilder gave you back a constant instead of an<br>
Instruction. This<br>
is why it returns a Value*. For a simple example, if you<br>
ask it to<br>
create "add i32 1, 2" it will not return an add<br>
instruction, it will<br>
instead return "i32 3" which is a ConstantInt.<br>
<br>
In your case, it returned to you a ConstantExpr whose<br>
getOpcode()<br>
shows Instruction::FAdd, and getOperand(0) and<br>
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<br>
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<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>
<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>>><br>
<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>><br>
<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<br>
instruction is not<br>
correct. There are probably some other problems. I<br>
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>
<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>>><br>
<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>><br>
<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>
<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>>><br>
<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>><br>
<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<br>
example,<br>
<br>
IRBuilder<> builder(&*pinst);<br>
Value *val = builder.CreateFAdd(LV, RV, "");<br>
<br>
How can I get the fadd instruction created<br>
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>
<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>>><br>
<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>><br>
<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<br>
my mind.<br>
But I<br>
just wanted to know if there was a<br>
generic way<br>
to save<br>
some code...<br>
<br>
On Thu, Apr 16, 2015 at 8:32 PM, Tim<br>
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>
<mailto:<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>
<mailto:<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>
<mailto:<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a><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.<br>
Realistically, just<br>
blindly<br>
replacing<br>
instructions with vector<br>
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<br>
function.<br>
<br>
Cheers.<br>
<br>
Tim.<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>
<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>>><br>
<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>><br>
<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>>>><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>
<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>>><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>
</div></div></blockquote>
<br>
</blockquote></div><br></div>