[LLVMdev] how to use "new instruction()"

zhi chen zchenhn at gmail.com
Fri Apr 17 00:43:01 PDT 2015


It seems that the problem was because I used  builder.CreateFAdd to create
a <2 x double> vectortype FADD instruction. It works if I use it to create
the scalar version FADD. I want to have an instruction like: *%2 = fadd <2
x double> undef, <2 x double> undef. *The following is the way I used to
create the vectorized FADD instruction:

//pInst is a double type instruction

  Type *vecTy = VectorType::get(pInst->getType(), 2);
  Value *emptyVec = UndefValue::get(vecTy);
  IRBuilder<> builder(&*pInst);
  Value *dupVal = builder.CreateFAdd(emptyVec, emptyVec, instName);

  std::cout << " dupVal " << *dupVal << "\n";

It outputs:  dupVal <2 x double> <double fadd (double undef, double undef),
double fadd (double undef, double undef)>

If I dyn_cast the dupVal to instruction type (dupInst) and print dupInst,
it outputs: "dupInst printing a <null> value"
But if I use Instruction *dupInst = (Instruction *) dupVal and print it,
I'll get:
dupInst <2 x double> <double fadd (double undef, double undef), double fadd
(double undef, double undef)>

It seems that if simply fails to generate the vectorized FADD instruction.
Anything wrong with my code?

Best,
Zhi






On Thu, Apr 16, 2015 at 11:55 PM, zhi chen <zchenhn at gmail.com> wrote:

> Yes. I was using this. It seems the produced instruction is not correct.
> There are probably some other problems. I need to recheck it. Thanks for
> your help, Daniel.
>
> Best,
> Zhi
>
> On Thu, Apr 16, 2015 at 11:40 PM, Daniel Berlin <dberlin at dberlin.org>
> wrote:
>
>> Value * is the instruction.
>>
>> use dyn_cast<Instruction> to get to it.
>>
>>
>> On Thu, Apr 16, 2015 at 11:39 PM zhi chen <zchenhn at gmail.com> wrote:
>>
>>> But IRBuilder.CreateXYZ only returns a "VALUE" type. Can I get the
>>> instruction created by it? For example,
>>>
>>> IRBuilder<> builder(&*pinst);
>>> Value *val = builder.CreateFAdd(LV, RV, "");
>>>
>>> How can I get the fadd instruction created by builder?
>>>
>>> On Thu, Apr 16, 2015 at 8:52 PM, zhi chen <zchenhn at gmail.com> wrote:
>>>
>>>> Yes. That's what I was the solution in my mind. But I just wanted to
>>>> know if there was a generic way to save some code...
>>>>
>>>> On Thu, Apr 16, 2015 at 8:32 PM, Tim Northover <t.p.northover at gmail.com
>>>> > wrote:
>>>>
>>>>> > I understand that I can detect the operation first, and use "create"
>>>>> to
>>>>> > create for each of them. But I don't if there is a generic way to do
>>>>> this
>>>>> > because if might be add/sub/mul... operations.
>>>>>
>>>>> I don't think there is. Realistically, just blindly replacing
>>>>> instructions with vector equivalents is only going to work in a few
>>>>> cases anyway. You're probably best to intentionally detect those cases
>>>>> and call the correct CreateXYZ function.
>>>>>
>>>>> Cheers.
>>>>>
>>>>> Tim.
>>>>>
>>>>
>>>>
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150417/c771e266/attachment.html>


More information about the llvm-dev mailing list