creating a vreg in eliminateFrameIndex()

Hello LLVM,
The ARM target sometimes adds an instruction with a virtual register
in eliminateFrameIndex():

https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMBaseRegisterInfo.cpp

This looks late for a virtual register to appear. Where is this vreg made real?

Thanks,
-steve

From: "Steve King" <steve@metrokings.com>
To: llvmdev@cs.uiuc.edu
Sent: Thursday, January 29, 2015 3:00:26 PM
Subject: [LLVMdev] creating a vreg in eliminateFrameIndex()

Hello LLVM,
The ARM target sometimes adds an instruction with a virtual register
in eliminateFrameIndex():

https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMBaseRegisterInfo.cpp

This looks late for a virtual register to appear. Where is this vreg
made real?

It is made real by the register scavanger (see scavengeFrameVirtualRegs in lib/CodeGen/PrologEpilogInserter.cpp.

-Hal

Hello LLVM,
The ARM target sometimes adds an instruction with a virtual register
in eliminateFrameIndex():

https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMBaseRegisterInfo.cpp

This looks late for a virtual register to appear. Where is this vreg made real?

The register scavenger should take care of such emergency post-RA register allocation. For thumb1, this happens in Thumb1RegisterInfo::saveScavengerRegister(): http://llvm.org/docs/doxygen/html/structllvm_1_1Thumb1RegisterInfo.html#ac73131381e7f5533f8e1e601f8e1c9ca

Cheers,

Jon

Thanks Jon and Hal for the helpful pointers. By returning true from
requiresRegisterScavenging() and requiresFrameIndexScavenging(), LLVM
handled all the scavenging effort. That is nearly painless for the
target, so why do some targets seem to do scavenging on their own?

When the scavenged register is loaded with a simple immediate, is it
safe to search the BB and replace other uses of the same immediate
with the reg? In my case this gives a code size reduction. The
search would stop on finding another use of the scavenged register.

Thanks,
-steve

From: "Steve King" <steve@metrokings.com>
To: jonathan@codesourcery.com
Cc: llvmdev@cs.uiuc.edu
Sent: Friday, January 30, 2015 10:52:19 AM
Subject: Re: [LLVMdev] creating a vreg in eliminateFrameIndex()

Thanks Jon and Hal for the helpful pointers. By returning true from
requiresRegisterScavenging() and requiresFrameIndexScavenging(), LLVM
handled all the scavenging effort. That is nearly painless for the
target, so why do some targets seem to do scavenging on their own?

Some of the targets pre-date the introduction of that feature.

When the scavenged register is loaded with a simple immediate, is it
safe to search the BB and replace other uses of the same immediate
with the reg? In my case this gives a code size reduction. The
search would stop on finding another use of the scavenged register.

Are you asking whether that would be safe to do on all targets?

-Hal

No, just a poor question -- I had in mind only my out-of-tree target.
I take the answer as "it depends on your target".

From: "Steve King" <steve@metrokings.com>
To: "Hal Finkel" <hfinkel@anl.gov>
Cc: llvmdev@cs.uiuc.edu, jonathan@codesourcery.com
Sent: Friday, January 30, 2015 11:20:43 AM
Subject: Re: [LLVMdev] creating a vreg in eliminateFrameIndex()

>> When the scavenged register is loaded with a simple immediate, is
>> it
>> safe to search the BB and replace other uses of the same immediate
>> with the reg? In my case this gives a code size reduction. The
>> search would stop on finding another use of the scavenged
>> register.
>
> Are you asking whether that would be safe to do on all targets?

No, just a poor question -- I had in mind only my out-of-tree target.
I take the answer as "it depends on your target".

Yes, especially not all targets can exchange immediates for registers in a trivial way.

-Hal