[LLVMdev] wide memory accesses
Jakob Stoklund Olesen
stoklund at 2pi.dk
Mon May 9 09:51:37 PDT 2011
On May 9, 2011, at 9:00 AM, Jonas Paulsson wrote:
> Hi,
>
> I am trying to take 16 bit memory reads and combine them to a single 32 bit read. I am having trouble to make the code simply read 32 bytes and the use the subregisters accordingly, without unnecessary copying.
>
> I have tried two techniques, in the MachineFunction:
>
> 1. replace the MachineOperands in the users of the data with the new register/subregister index. This yields an assert failure during VirtRegRewriter, in substPhysReg: "Invalid SubReg for physical register", after the Two-address rewrote this:
>
> %reg16445<def> = add %reg16507:hi16, %reg16510:hi16 ; 32bit:16507,16510, 16bit: 16445
> prepend: %reg16445<def> = COPY %reg16507;
> rewrite to: %reg16445<def> = addh_1_8 %reg16445:hi16, %reg16510:hi16
>
> In my eyes, there should not have been a subreg 'hi16' for the 16445 reg - this reg is 16 bits. I would have wished that the 16507:hi16 be interpreted as the corresponding subregister, and thus generated in the COPY with a :hi16. It is all right that the 16445 is of 16 bits, this is correct, but then it is used incorrectly with a :hi16 subregister value ?? Any ideas?
If you are doing this before the register allocator passes, you must make sure that the code preserves SSA form. That can be difficult to do when dealing with sub-registers. Other targets just emit EXTRACT_SUBREG / INSERT_SUBREG and let the coalescer deal with it.
It looks like TwoAddressInctructionPass is not ready to deal with subreg indexes either, it is creating wrong code in your example.
I recommend:
> 2. Insert COPY's, but these would not get coalesced away, so instead of saving instructions I ended up with one load and two moves...:-( How could I get the wide load to simply be used intelligently by COPYing to the old virtual registers?
You need to implement getMatchingSuperRegClass in your register info class. That will give the coalescer the needed information to join subreg copies.
/jakob
More information about the llvm-dev
mailing list