This is an archive of the discontinued LLVM Phabricator instance.

[X86] Prefer VEX encoding in X86 assembler.
ClosedPublic

Authored by LuoYuanke on Oct 11 2021, 5:21 AM.

Details

Summary

This patch is to order the AVX instructions ahead of AVX512 instructions
in the matching table so that the AVX instructions can be matched first.
Thanks Craig for the idea.

Diff Detail

Event Timeline

LuoYuanke created this revision.Oct 11 2021, 5:21 AM
LuoYuanke requested review of this revision.Oct 11 2021, 5:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2021, 5:21 AM

Does this pass tests on all targets? I didn't check myself.

Does this pass tests on all targets? I didn't check myself.

It passes X86 target. I'll test it on all targets.

There are 16 test case fails.

Failed Tests (16):
  LLVM :: MC/AMDGPU/expressions.s
  LLVM :: MC/AMDGPU/gfx1011_dlops.s
  LLVM :: MC/AMDGPU/gfx10_asm_smem.s
  LLVM :: MC/AMDGPU/gfx7_asm_mubuf.s
  LLVM :: MC/AMDGPU/gfx8_asm_mubuf.s
  LLVM :: MC/AMDGPU/gfx90a_asm_features.s
  LLVM :: MC/AMDGPU/gfx90a_ldst_acc.s
  LLVM :: MC/AMDGPU/gfx9_asm_mubuf.s
  LLVM :: MC/AMDGPU/gfx9_asm_smem.s
  LLVM :: MC/AMDGPU/literalv216.s
  LLVM :: MC/AMDGPU/mubuf.s
  LLVM :: MC/AMDGPU/smem.s
  LLVM :: MC/AMDGPU/trap.s
  LLVM :: MC/AMDGPU/vop3-literal.s
  LLVM :: MC/Mips/micromips32r6/valid.s
  LLVM :: MC/WebAssembly/tables.s
LuoYuanke added inline comments.Oct 11 2021, 6:50 AM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
648

Is there any approach to check it is X86 target?

skan added inline comments.Oct 12 2021, 1:25 AM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
648

Sure. You can check TheDef->isSubClassOf("X86Inst")

LuoYuanke added inline comments.Oct 12 2021, 1:58 AM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
648

Great! I'll update the patch.

LuoYuanke updated this revision to Diff 378921.Oct 12 2021, 2:00 AM

Check "X86Inst" to order the match table for X86 specificly.

The test case passes on all target.

I personally prefer this patch, because it is more general and is easier to implement.

skan added inline comments.Oct 12 2021, 7:44 PM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
639–640

Suggestion: This is X86-specific code in target-independent file. Please add some comments about why you specialize the code for X86 here and how the strict total order of ID is defined.

LuoYuanke updated this revision to Diff 379339.Oct 13 2021, 4:46 AM

Address Shengchen's comments.

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

We can see in line 636, it also do some specific things for ARM. We can also see ReportMultipleNearMisses is added for ARM.

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

We can see in line 636, it also do some specific things for ARM. We can also see ReportMultipleNearMisses is added for ARM.

I think you understand that i'm not talking about doing specific for target X - adding new hooks is fine,
but specifically about checking for the subclass name and doing different stuff based on that.

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

We can see in line 636, it also do some specific things for ARM. We can also see ReportMultipleNearMisses is added for ARM.

I think you understand that i'm not talking about doing specific for target X - adding new hooks is fine,
but specifically about checking for the subclass name and doing different stuff based on that.

Do you have any suggestions? I don't know if there is any mechanism that can invoke target specific function in generic code in tablegen.

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

We can see in line 636, it also do some specific things for ARM. We can also see ReportMultipleNearMisses is added for ARM.

I think you understand that i'm not talking about doing specific for target X - adding new hooks is fine,
but specifically about checking for the subclass name and doing different stuff based on that.

Do you have any suggestions? I don't know if there is any mechanism that can invoke target specific function in generic code in tablegen.

I guess i would suggest dealing with that in the backend itself.

pengfei added inline comments.Oct 13 2021, 8:12 AM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
624

I have a question here. AVX512 instructions have larger register class, e.g. VR128X vs. VR128. Why doesn't (Could) the code work for them?

pengfei added inline comments.Oct 13 2021, 8:15 AM
llvm/utils/TableGen/AsmMatcherEmitter.cpp
624

Oh, it seems they are all the same since only GPRs and memory.

How about we add a EncodingCost to the base class Instruction and set a high cost for EVEX? Or we can reuse the Size in it, since all X86 instructions set it to 0. We can use it as the encoding cost.

skan added a comment.Oct 13 2021, 7:05 PM

Having something specific to some specific target in a generic code
(esp. if there is no precedent for it) seems conceptually wrong.

We can see in line 636, it also do some specific things for ARM. We can also see ReportMultipleNearMisses is added for ARM.

I think you understand that i'm not talking about doing specific for target X - adding new hooks is fine,
but specifically about checking for the subclass name and doing different stuff based on that.

Do you have any suggestions? I don't know if there is any mechanism that can invoke target specific function in generic code in tablegen.

I guess i would suggest dealing with that in the backend itself.

@lebedev.ri How about adding a hook such as hasPositionOrder, which means the order in which the instructions appear in TD file affects the order of assembler matching ?

LuoYuanke updated this revision to Diff 380167.Oct 16 2021, 4:19 AM

Address Pengfei and Shengchen's comments. Their ideas are similar.

pengfei added inline comments.Oct 16 2021, 4:53 AM
llvm/include/llvm/Target/Target.td
656–659

Redundant?

LuoYuanke updated this revision to Diff 380174.Oct 16 2021, 5:16 AM

Address pengfei's comments.

LuoYuanke added inline comments.Oct 16 2021, 5:18 AM
llvm/include/llvm/Target/Target.td
656–659

Redundant?

Opps! I forget to delete it.

skan accepted this revision.Oct 16 2021, 7:51 AM

LGTM

This revision is now accepted and ready to land.Oct 16 2021, 7:51 AM
This revision was automatically updated to reflect the committed changes.