[LLVMdev] How to lower the intrinsic function 'llvm.objectsize'?

Nuno Lopes nunoplopes at sapo.pt
Sun Nov 9 02:39:33 PST 2014


Hi,

It depends on what you're trying to accomplish.
I guess for KLEE it would be sufficient to ignore the intrinsic (as you say, 
replace it with 0/-1). InstCombine will try to lower it properly. If it 
fails, it means that later CodeGen will ignore the intrinsic as well (i.e., 
replace it with 0/-1 and fold comparisons/branches depending on it).  So, in 
this way you would mimic LLVM's behavior.
If you want to do full-blown verification, then you'd need to consider the 
cases where the compiler might be able to lower the intrinsic and the cases 
it won't. For these, lowering the intrinsic with the API I mentioned would 
be better, but then you would need to fork and execute both branches: when 
the compiler can and cannot lower the intrinsic.  Probably not worth it.

Nuno

-----Original Message----- 
From: Dan Liew
Sent: Friday, November 07, 2014 11:13 AM
To: Dingbao Xie
Cc: Matt Arsenault ; LLVM Developers Mailing List ; Daniel Dunbar ; 
nunoplopes at sapo.pt
Subject: Re: [LLVMdev] How to lower the intrinsic function 
'llvm.objectsize'?

Hi Dingbao,

On 5 November 2014 22:37, Dingbao Xie <xiedingbao at gmail.com> wrote:
> Thanks for your reply.
> I'm attempting to expand KLEE to support this intrinsic function.
> That's why I need to handle this myself.
> According to the reply, the correct implementation should first find the
> definition of the object and then determine the
> size of the object.
> BTW, can I just refer to the implementation in InstCombineCalls.cpp.

Please see this [1] issue on KLEE's issue tracker.

After talking to Daniel (CC'ed) I was under the impression that the
easiest thing to do would be to treat these as no-ops rather than
trying to lower them.

Reading the docs on llvm.objectsize couldn't we just be really lazy
and return 0 or -1 (indicating unknown) depending on the value of the
"min" argument? If there are programs where control flow depends on
the return value of llvm.objectsize() this would probably break things
but I don't know if clang ever generates IR in that form.

What Nuno just suggested sounds quite promising way to do this that
isn't as lazy as what I suggested.

[1] https://github.com/klee/klee/issues/33
[2] http://llvm.org/docs/LangRef.html#llvm-objectsize-intrinsic

Thanks,
Dan. 




More information about the llvm-dev mailing list