This is an archive of the discontinued LLVM Phabricator instance.

[X86] Make sure we do not clobber RBX with mwaitx when used as a base pointer.
ClosedPublic

Authored by pgousseau on Jan 27 2020, 7:15 AM.

Details

Summary

mwaitx uses EBX as one of its argument.
Using this instruction clobbers RBX as it is defined to hold one of the input. When the backend uses dynamically allocated stack, RBX is used as a reserved register for the base pointer.

This patch is adapted from @qcolombet patch for cmpxchg at r263325.

This fixes PR43528.

Diff Detail

Event Timeline

pgousseau created this revision.Jan 27 2020, 7:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2020, 7:15 AM

Is this subject to the same problem as PR42064?

Is this subject to the same problem as PR42064?

Thanks for pointing this issue, yes I believe this change will have the same problem in cases where stack realignment occurs after mwaitx pseudo instruction is generated.
If I understand the conclusion of the PR is that the decision to save/restore base pointer needs to be done after PEI? I will try that approach.

pgousseau updated this revision to Diff 287013.Aug 21 2020, 5:20 AM

Updated the patch to handle the case described in PR42064 where a separate basic block demands the use of a base pointer.
In that case we do the codegen of mwaitx during custom insertion.

craig.topper added inline comments.Aug 21 2020, 11:14 AM
llvm/lib/Target/X86/X86ISelLowering.cpp
25820

Can we just always use MWAITX_DAG and use the !hasBasePointer part of the custom inserter?

25838

Is the Glue result needed?

pgousseau updated this revision to Diff 287322.Aug 24 2020, 3:13 AM
  • Always use MWAITX_DAG
  • Remove uneeded Glue
pgousseau marked 2 inline comments as done.Aug 24 2020, 3:30 AM
pgousseau added inline comments.
llvm/lib/Target/X86/X86ISelLowering.cpp
25820

I assumed there might be missed optimisations opportunities, but havent managed to find an example actually so always using MWAITX_DAG sounds good!

25838

Removed! thanks!

This revision is now accepted and ready to land.Aug 25 2020, 10:02 AM