[PATCH] Change MachineOperand OpKind to a bitfield

Pete Cooper peter_cooper at apple.com
Mon Apr 20 17:36:50 PDT 2015


> On Apr 20, 2015, at 5:25 PM, Matthias Braun <mbraun at apple.com> wrote:
> 
> 
>> On Apr 20, 2015, at 4:10 PM, Pete Cooper <peter_cooper at apple.com> wrote:
>> 
>> Hi Rafael
>> 
>> MachineOperand::OpKind is an unsigned char, followed by 24-bits of bitfields.  clang is able to make all of that take 32-bits of space, but it generates pretty nasty code to do so.
>> 
>> OpKind itself is loaded and stored as an i8 and so gets very nice IR.  However, loading an entry from one of the bitfields results in a load of an i24, then masking operations.  Given that i24 isn’t legal, the legalizer goes to great lengths to make this work, typically splitting it in to i8 and i16 operations.
> I don't know the actual clang code, but isn't the canonical codegen for something like the following "unsigned SubReg_TargetFlags : 12;" to load an "unsigned" value and shift/mask that? Why does it use i24?
Attached code to demonstrate this.  Here’s a reduced version of MachineOperand compiled with and without the change.

To answer your question, clang has decided that the 24 bits total of bitfields should be represented as a [3 x i8].  So to read one of the bitfields, it casts the [3 x i8]* to i24* then does a load.  I guess it just wants to always load and store the whole bitfield when operating on any one piece of it.  

I’m not sure if this is a requirement of C++ or not.  Personally, i’d like clang to use powers of 2 which are a multiple of 8 (i.e., 8, 16, 32, 64) for bitfield operations in the IR, but i don’t know if it can or not.

Pete

-------------- next part --------------
A non-text attachment was scrubbed...
Name: after.ll
Type: application/octet-stream
Size: 2833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150420/351779b0/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: after.s
Type: application/octet-stream
Size: 2031 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150420/351779b0/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mo.cpp
Type: application/octet-stream
Size: 574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150420/351779b0/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: before.s
Type: application/octet-stream
Size: 1782 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150420/351779b0/attachment-0003.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: before.ll
Type: application/octet-stream
Size: 2918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150420/351779b0/attachment-0004.obj>
-------------- next part --------------

> 
> - Matthias



More information about the llvm-commits mailing list