This is an archive of the discontinued LLVM Phabricator instance.

[X86][AsmParser] Omit predicate In64BitMode for instructions w/ GP64 operand in X86InstrArithmetic.td, NFCI
AbandonedPublic

Authored by skan on May 4 2023, 2:54 AM.

Details

Summary

As we discussed in D138639, we usually omit In64BitMode on instructions that
have a GR64 operand b/c

  1. Assembler would never parse a GR64 register name outside of 64-bit mode
  2. GR64/i64 is not legal during ISEL outside of 64-bit mode
  3. Adding them might increase the size of the table in X86GenDAGISel.inc

For instructions that do not have an explicit GR64 operand, they're assumed to have an implicit In64BitMode predicate when W bit is set in AsmParser.

Since no test fails w/o the change in AsmParser, I add a test in this patch.

I will do similar clean in other files if this patch is accepted.

Diff Detail

Event Timeline

skan created this revision.May 4 2023, 2:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 2:54 AM
skan requested review of this revision.May 4 2023, 2:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2023, 2:54 AM
pengfei requested changes to this revision.May 4 2023, 3:02 AM

I think we cannot remove it for memory only variants. The addr is legal on both 32-bits and 64-bits.

This revision now requires changes to proceed.May 4 2023, 3:02 AM
skan added a comment.EditedMay 4 2023, 3:51 AM

I think we cannot remove it for memory only variants. The addr is legal on both 32-bits and 64-bits.

But looking at the definition of loadi64

def loadi64  : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;

, which is the operator of addr, it seems loadi64 is only matched in 64-bit mode due to i64.

pengfei accepted this revision.May 4 2023, 8:11 AM

I think we cannot remove it for memory only variants. The addr is legal on both 32-bits and 64-bits.

But looking at the definition of loadi64

def loadi64  : PatFrag<(ops node:$ptr), (i64 (load node:$ptr))>;

, which is the operator of addr, it seems loadi64 is only matched in 64-bit mode due to i64.

That makes sense to me. Although I still have concerns about that, I cannot find a evidence for now. So LGTM.

This revision is now accepted and ready to land.May 4 2023, 8:11 AM
craig.topper requested changes to this revision.May 4 2023, 9:54 AM

None of these instructions have GPR operands to preventing parsing.

llvm/lib/Target/X86/X86InstrArithmetic.td
602–603

This instruction doesn't have a GPR operand. It's just incq (%rax) If the pointer doesn't have any register or uses 32 bit registers what prevents it from parsing?

This revision now requires changes to proceed.May 4 2023, 9:54 AM
skan updated this revision to Diff 520056.May 6 2023, 2:32 AM

Check W bit in X86AmsParser

skan retitled this revision from [X86] Omit predicate In64BitMode for instructions w/ GP64 operand in X86InstrArithmetic.td, NFCI to [X86][AsmParser] Omit predicate In64BitMode for instructions w/ GP64 operand in X86InstrArithmetic.td, NFCI.May 6 2023, 2:37 AM
skan edited the summary of this revision. (Show Details)
skan edited the summary of this revision. (Show Details)May 6 2023, 2:39 AM
skan added inline comments.May 6 2023, 2:43 AM
llvm/lib/Target/X86/X86InstrArithmetic.td
602–603

This instruction doesn't have a GPR operand. It's just incq (%rax) If the pointer doesn't have any register or uses 32 bit registers what prevents it from parsing?

@craig.topper We can check if W bit is set.

skan updated this revision to Diff 520059.May 6 2023, 2:44 AM

Remove redundant blank in test

craig.topper added inline comments.May 6 2023, 9:13 AM
llvm/lib/Target/X86/X86InstrArithmetic.td
602–603

Why create a new way to do this when we already have predicates?

craig.topper added inline comments.May 6 2023, 9:31 AM
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
4193

The issue also appears on the VEX and EVEX encoded memory form of vextractps.

skan abandoned this revision.May 6 2023, 5:54 PM
skan added inline comments.
llvm/lib/Target/X86/X86InstrArithmetic.td
602–603

I intended to simplify the code in TD. But I agreed that it would make the code in AsmParser look worse. I will close this.

pengfei added inline comments.May 6 2023, 6:40 PM
llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
4193

Should !(TSFlags & X86II::EncodingMask) be used to prevent for VEX and EVEX? Anyway, I agree it's a bit big hammer for this.