[llvm-dev] Question about using IRBuilder::CreateIntrinsic for a variadic intrinsic

242 views
Skip to first unread message

Riyaz Puthiyapurayil via llvm-dev

unread,
Oct 5, 2020, 3:30:07 PM10/5/20
to llvm...@lists.llvm.org

I have a variadic intrinsic that is defined as something like this:

 

def int_foobar : Intrinsic<[llvm_anyint_ty],

                            [llvm_vararg_ty],

                            [IntrNoMem, IntrSpeculatable]>;

 

 

When I construct a call to the above intrinsic with IRBuilder::CreateIntrinsic, it mangles the intrinsic name with the return type (i64) and the actual argument types i32.i32.  The mangled name then becomes @llvm.foobar.i64.i32.i32

 

However this causes the Verifier to fail with:

 

Intrinsic name not mangled correctly for type arguments! Should be: llvm.foobar.i64

 

It seems to me the problem occurs when the return type is overloaded. If I change the return type for the intrinsic in Intrinsics.td from llvm_anyint_ty to a specific type, say llvm_i64_ty, then it works without any issues.

 

Is this a limitation or a bug in the verifier or builder? Should I explicitly create a declaration for the intrinsic for each return type, before calling IRBuilder::CreateIntrinsic? I haven’t checked it if it would work in my code (but writing it like that in assembly and making the calls seems to work). More specifically the following works (declaring before or after the call seems to work in assembly):

 

  %a = call i64 (…) @llvm.foobar.i64(i32 %b, i32 %xc)

:

:

declare i64 @llvm.foobar.i64(…)

 

Any comments? How is the call to such an intrinsic supposed to be constructed with IRBuilder?

 

/Riyaz

Riyaz Puthiyapurayil via llvm-dev

unread,
Oct 5, 2020, 4:28:44 PM10/5/20
to llvm...@lists.llvm.org

Should I omit the actual argument types corresponding to the variadic arguments? Is that how CreateIntrinsic should be called?

Nicolai Hähnle via llvm-dev

unread,
Oct 7, 2020, 3:08:11 PM10/7/20
to Riyaz Puthiyapurayil, llvm...@lists.llvm.org
On Mon, Oct 5, 2020 at 10:28 PM Riyaz Puthiyapurayil via llvm-dev
<llvm...@lists.llvm.org> wrote:
> Should I omit the actual argument types corresponding to the variadic arguments? Is that how CreateIntrinsic should be called?

CreateIntrinsic expects you to pass _only_ the types corresponding to
llvm_any*_ty types.

Cheers,
Nicolai

> _______________________________________________
> LLVM Developers mailing list
> llvm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

--
Lerne, wie die Welt wirklich ist,
aber vergiss niemals, wie sie sein sollte.
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Reply all
Reply to author
Forward
0 new messages