This is an archive of the discontinued LLVM Phabricator instance.

[x86 - inline asm] Favor reg over memory in asm w/ one input parameter
Needs ReviewPublic

Authored by Gerolf on Apr 24 2015, 5:33 PM.

Details

Reviewers
echristo
Summary

When more than one location for an asm parameter is specified,
the most general is selected. In the specific case of an 'rm' constraint
this gives higher priority to a memory vs register location.
In case there is only one input operand this is too conservative.
The purpose of this patch is to allow higher priority for the
register location in that case.

Diff Detail

Event Timeline

Gerolf updated this revision to Diff 24423.Apr 24 2015, 5:33 PM
Gerolf retitled this revision from to [x86 - inline asm] Favor reg over memory in asm w/ one input parameter.
Gerolf updated this object.
Gerolf edited the test plan for this revision. (Show Details)
Gerolf added a reviewer: echristo.
Gerolf added a subscriber: Unknown Object (MLST).
echristo edited edge metadata.Apr 27 2015, 3:55 PM

Hi Gerolf,

I'm not sure this is the right way to go. What I'm assuming (since you don't mention) the case that you have is something where the operand is actually already in a register and you want to just go ahead and use that rather than picking the alternative that copies it to memory? Why not solve that problem by looking through the various possible constraints and if the operand you want is already in a location then pick that and worry about forcing as separate?

-eric

Hi Eric

yes, there are more general ways of handling this, and for a single operand your suggestion improves on the implementation I currently have. Wrt to the more general solution it seems that it could result in a problem - at least when implemented naively like for one operand at a time - e.g. when an operand resides in a location needed by another one. This is indicated by a comment in ChooseConstraint() " Ideally, we would pick the most specific constraint possible: if we have something that fits into a register, we would pick it. The problem here is that if we have something that could either be in a register or in memory that use of the register could cause selection of *other* operands to fail: they might only succeed if we pick memory. ".
The most general route for handling this would be to enhance cg copy prop to handle cases like vreg->mem etc. But that is more longer term and would be an overkill for the isolated instance at hand.
So I think I go ahead and add a location check to my current code. Would that stand a chance to pass your LGTM threshold?

Cheers
Gerolf

Gerolf updated this revision to Diff 24595.Apr 28 2015, 8:43 PM
Gerolf edited edge metadata.

Only give register preference to the parameter when it resides in a register as Eric suggested.