[LLVMdev] Optimization opportunity
Chris Lattner
sabre at nondot.org
Tue Sep 7 17:51:53 PDT 2004
On Sat, 28 Aug 2004, Jeff Cohen wrote:
> I succumbed to temptation and made the improvement. Diffs are attached
> for X86ISelSimple.cpp and X86InstrBuilder.h.
The patches look great, that's a very elegant way to address the problem,
and also simplified some code, thanks!
> I determined that the reason two instructions are generated in the first
> place, instead of being folded immediately into one, is because locals
> do not have a physical offset assigned at that time. There is a
> peephole optimization pass after the stack frame is finalized, but the
> problem with folding them there is that the physical registers have also
> been assigned, so register CX (in this case) would be wasted.
Yup.
> So I generalized the concept of a "full address". There were four
> variables, base reg, scale, index reg and displacement, that were being
> passed around. I converted them into a single struct and added a new
> type field that allows the base reg to instead be a frame index. The
> extra lea instruction is now folded immediately, and the code for
> processing store instructions shrinks quite nicely.
Sounds good.
> This should be generalizable even further to handle global variables. I
> didn't go that far, because it appeared there may be other work
> required. It wasn't clear a displacement to a global was supported.
That would be cool as well. A displacement from a global should be
supported. Look at the code generated for:
int G;
void foo() { G = 4; }
... and you'll see what I mean. :)
-Chris
--
http://llvm.org/
http://nondot.org/sabre/
More information about the llvm-dev
mailing list