This is an archive of the discontinued LLVM Phabricator instance.

[x86] Fold extract_vector_elt of a load into the load's address computation.
ClosedPublic

Authored by Bigcheese on Apr 14 2014, 7:59 PM.

Details

Summary

An address only use of an extract element of a load can be simplified to a
load. Without this the result of the extract element is spilled to the
stack so that an address is available.

Diff Detail

Event Timeline

This looks like a really nice improvement, and you're right, probably not just for x86.

I suggest looking into making this a target-independent DAG combine that can be predicated on queries to TargetLowering about what types and operations are legal to see when it's profitable. I suspect this is going to be the right thing to do for pretty much all CPU targets.

Hi Michael,

DAGCombiner has a load slicing mechanism what tries to produce target friendly loads. Maybe we could extend this mechanism to handle this kind of cases.
Do not know how easy that would be, but that seems to me like the natural place to start :).

You can take a look at DAGCombiner::SliceUpLoad.

Thanks,
-Quentin

Bigcheese updated this revision to Diff 8784.Apr 23 2014, 5:54 PM
Bigcheese updated this object.
Bigcheese edited edge metadata.

Moved to DAGCombiner and refactored the existing load slicing code.

Hi Michael,

This LGTM with one remark, I leave it to you whether or not you want to address it since Nadav already gave his LGTM.

I do not particularly like the use of the lambda here. I think it would have been clearer to explicitly add the few more variables that we use (ConstEltNode, NewLowd, EltNo) and have a new (documented) private member function.
I see two advantages of using a member function instead of the lambda:

  • DAGCombiner::visitEXTRACT_VECTOR_ELT would be easier to read and understand.
  • The member function can be properly documented.

What do you think?

Thanks,
-Quentin

Bigcheese accepted this revision.May 28 2014, 6:52 PM
Bigcheese added a reviewer: Bigcheese.
This revision is now accepted and ready to land.May 28 2014, 6:52 PM
Bigcheese closed this revision.May 28 2014, 6:53 PM

Committed as r209788 with fixes.

Thanks!

-Quentin