This is an archive of the discontinued LLVM Phabricator instance.

[X86][MC] Optimize more instructions from VEX3 to VEX2 and fix the incorrect control flow in X86MCInstLower
AbandonedPublic

Authored by skan on May 12 2023, 5:37 AM.

Details

Summary

X86MCInstLower::Lower has a huge switch-cases, from which D150068 removed
VMOVSS. It caused the unoptimized VMOVSS to wrongly fall
to the default label. The default label exchanged the 1st and 2nd
operand, but we should exchange the 0th and 2nd operand.

In this patch, we move the code in the default lable about "VEX3 to
VEX2" to the function X86::optimizeInstFromVEX3ToVEX2 to fix the bug.

Since the function is shared, a side effect is that more encoding
optimizations are done on the Asmparser side. Considering we already
use reverse-encoding for optimization in AsmParser before this patch,
I believe the change is positive and expected.

Diff Detail

Event Timeline

skan created this revision.May 12 2023, 5:37 AM
Herald added a project: Restricted Project. · View Herald Transcript
skan requested review of this revision.May 12 2023, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 12 2023, 5:37 AM
bgraur added a subscriber: bgraur.May 12 2023, 6:55 AM

The patch seems to fix the problem, but it looks like it potentially changes generated code in more cases, and thus it might introduce more issues. Can we go the safe route: revert https://reviews.llvm.org/D150068 first and then land it together with the fix after it gets sufficient review?

Apart from that, the pre-merge checks are failing.

skan added a comment.EditedMay 12 2023, 7:11 AM

The patch seems to fix the problem, but it looks like it potentially changes generated code in more cases, and thus it might introduce more issues. Can we go the safe route: revert https://reviews.llvm.org/D150068 first and then land it together with the fix after it gets sufficient review?

Apart from that, the pre-merge checks are failing.

It seems that the pre-merge fails due to commits related to f470922a299f6036259c703a534a9b1e60573df7, not this.

And the tests pass after rebasing to ee75422ce1854208b12eb114e62ff9e3042570c7

skan added a comment.May 12 2023, 7:40 AM

@bgraur I will revert D150068 first, so that we won't have to revert two separate commits if there is a coming issue. The fix in this patch seems straightforward to me and since D150068 was reviewed already, I will try to reland it with this fix.

skan abandoned this revision.May 12 2023, 7:52 AM

@bgraur I will revert D150068 first, so that we won't have to revert two separate commits if there is a coming issue. The fix in this patch seems straightforward to me and since D150068 was reviewed already, I will try to reland it with this fix.

Perfect @skan Thanks a lot for reverting first