This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add a private member function determinePaddingPrefix for X86AsmBackend
ClosedPublic

Authored by skan on Feb 28 2020, 8:20 AM.

Details

Summary

X86 can reduce the bytes of NOP by padding instructions with prefixes to get a better peformance in some cases. So a private member function determinePaddingPrefix is added to determine which prefix is the most suitable.

Diff Detail

Event Timeline

skan created this revision.Feb 28 2020, 8:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 28 2020, 8:20 AM
skan updated this revision to Diff 247425.Feb 29 2020, 12:00 AM
skan retitled this revision from [X86] Add a local function DeterminePaddingPrefix for X86AsmBackend to [X86] Add a private member function determinePaddingPrefix for X86AsmBackend.
skan edited the summary of this revision. (Show Details)

Lowercase the first character of the function name and make the function private

skan updated this revision to Diff 247435.Feb 29 2020, 2:58 AM

delete the unintentional static

skan updated this revision to Diff 247489.Mar 1 2020, 12:11 AM

Add one comment for the encoding values for segment overide prefixes.

skan updated this revision to Diff 247490.Mar 1 2020, 12:41 AM

Fix the error reported by clang-tidy

reames accepted this revision.Mar 2 2020, 2:50 PM

LGTM

This revision is now accepted and ready to land.Mar 2 2020, 2:50 PM
skan added a comment.Mar 2 2020, 7:44 PM

@craig.topper the logic of checking the existing segment override prefix for instruction is kind of complicated, does it look good to you?

Do you have a plan how determinePaddingPrefix will be used? Without a plan, there may be some churn that moves things around. The plan should also include how the complex logic will be tested eventually.

skan added a comment.Mar 2 2020, 10:16 PM

Do you have a plan how determinePaddingPrefix will be used? Without a plan, there may be some churn that moves things around. The plan should also include how the complex logic will be tested eventually.

Philip prototyped what prefix padding for relaxable instructions might look like in D75203, determinePaddingPrefix is planed to be used to determine the appropriate prefix in the framework.

MaskRay added inline comments.Mar 3 2020, 8:44 AM
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
357

The variable Opcode can be omitted.

359

Consider omitting TSFlags. It is used just twice.

361

The variable CurOp can be omitted.

375

The variable Form can be omitted.

skan updated this revision to Diff 248104.Mar 3 2020, 9:51 PM

Address review comments

skan marked 3 inline comments as done.Mar 3 2020, 9:52 PM
skan added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
359

Prefer to keep unchanged.

This revision was automatically updated to reflect the committed changes.
glider added a subscriber: glider.Mar 15 2023, 6:28 AM
glider added inline comments.
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
350

Hi Shengchen,

Out of curiosity, why does this feature use CS instead of DS for instruction padding?

Also, is there an easy way to trigger this behavior in Clang? I couldn't find any tests for this functionality.

Thanks!

Herald added a project: Restricted Project. · View Herald TranscriptMar 15 2023, 6:28 AM
Herald added a subscriber: pengfei. · View Herald Transcript
skan added inline comments.Mar 15 2023, 7:07 AM
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
350

Hi @glider. the behavior here is to align with GAS, I don't know if there is a specific reason to use CS here. I doubt it's more like a decision.

You can find the tests here

llvm/test/MC/X86/prefix-padding-64.s
llvm/test/MC/X86/prefix-padding-32.s