This is an archive of the discontinued LLVM Phabricator instance.

Correct the sort logic in AsmMatcherEmmitter.cpp
ClosedPublic

Authored by XinWang10 on May 12 2023, 3:14 AM.

Details

Summary

The logic from line 633 to 640 is specific for ARM as the comments said, it will make all the targets will prefer to using instruction with more predicates when compiler do AsmMatching.
And for code from line 642 to 649, X86 want to use the order records written in source file to sort the instructions. So X86 could be affected by this logic. (These code could be arrived only by X86)
After change this, seems AVX instructions have not be affected but it exposed some other errors for instruction push and call.
CALLpcrel16 could not be used in 64 bit mode, we need add Predicate for it. And for push instruction, previously because pushi32 has predicates = [Not64bitmode], so it precede pushi16, which is incorrect here, we should get pushw here and it also align with gcc.

Diff Detail

Event Timeline

XinWang10 created this revision.May 12 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 3:14 AM
XinWang10 requested review of this revision.May 12 2023, 3:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 3:14 AM
skan added inline comments.May 12 2023, 7:01 AM
llvm/test/MC/X86/x86_64-encoding.s
5

Put this in a test for 16-bit mode. Otherwise we would lose test coverage.

barannikov88 added inline comments.May 12 2023, 7:15 AM
llvm/test/MC/X86/pr22028.s
17

Is this correct? 65536 does not fit into a 16-bit word.

skan added inline comments.May 12 2023, 7:58 AM
llvm/test/MC/X86/pr22028.s
17

It aligns with the GAS's behavior.

bash$ cat 1.s

.code16
push 65536

bash$ as 1.s -o 1.o
bash$ objdump -M i8086 -d 1.o

0000000000000000 <.text>:
   0:   ff 36 00 00             pushw  0x0
XinWang10 updated this revision to Diff 522405.May 15 2023, 6:45 PM
  • add test for call in 16 bit
skan added a comment.May 15 2023, 9:39 PM

Can you make the summary easier to read? Developers have to check the line number of the source file to understand it, if you mention the logic by line 633

XinWang10 edited the summary of this revision. (Show Details)May 15 2023, 10:47 PM
XinWang10 edited the summary of this revision. (Show Details)
skan accepted this revision.May 15 2023, 10:57 PM

LGTM

This revision is now accepted and ready to land.May 15 2023, 10:57 PM
This revision was automatically updated to reflect the committed changes.