[llvm-dev] [RFC] A new intrinsic, `llvm.blackbox`, to explicitly prevent constprop, die, etc optimizations

Daniel Berlin via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 11 10:41:22 PST 2015


On Wed, Nov 11, 2015 at 10:32 AM, Reid Kleckner <rnk at google.com> wrote:

> I think the idea is to model the intrinsic as a normal external function
> call:
>
- Can read/write escaped memory
>
- Escapes pointer args
> - Functionattrs cannot infer anything about it
> - Returns a pointer which may alias any escaped data
>
> As you point out so nicely, there is already a list of stuff that external
function calls may do, but we may be able to prove things about them anyway
due to attributes, etc.

So it's not just an external function call, it's a super-magic one.

Now, can we handle that?
Sure.

For example,  i can move external function calls if i can prove things
about their dependencies, and the above list is not sufficient to prevent
me from moving (or PRE'ing) most of the blackbox calls that just take
normal non-pointer args.
Is that going to be okay?

(Imagine, for example, LTO modes where i can guarantee i have the entire
program, etc.
You still want blackbox to be magically special in these modes, even though
nothing else is).





> It's obvious how this works at the IR level, but I'm not sure what would
> happen in the backend. If you compile the intrinsic to nothing but a
> virtual register copy, MI optimizations will kick in. You might get away
> with compiling it to a volatile store/load, and hope that the time for
> high-level memory optimizations like GVN is over.
>
> On Mon, Nov 9, 2015 at 8:58 PM, Daniel Berlin <dberlin at dberlin.org> wrote:
>
>>
>>
>> On Mon, Nov 9, 2015 at 7:46 PM, Reid Kleckner <rnk at google.com> wrote:
>>
>>> One thing that volatile doesn't do is escape results that have been
>>> written to memory.
>>>
>>>
>> Honestly, i'd probably rather see attributes or something than this
>> intrinsic.
>>
>> That said ....
>>
>>
>>
>>> The proposed blackbox intrinsic is modeled as reading and writing any
>>> pointed to memory, which is useful.
>>>
>>>
>> The proposed intrinsic does not have a really well defined exact set of
>> semantics.
>> If it did, and those semantics made sense, i think you'd see a lot less
>> pushback.
>>
>>
>>> I also think blackbox will be a lot easier for people to use than empty
>>> volatile inline asm and volatile loads and stores. That alone seems worth
>>> something. :)
>>>
>>>
>> Yes, but at the same time, it seems very "Do What I Mean".
>>
>> Those kinds of intrinsics rarely turn out to be sane and maintainable ;-)
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151111/485fdf64/attachment.html>


More information about the llvm-dev mailing list