Skip to content

Commit 120818c

Browse files
committed
[X86] Support EVEX compression for EGPR
1 parent 93c8468 commit 120818c

13 files changed

+53
-43
lines changed

llvm/lib/Target/X86/X86CompressEVEX.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,12 @@ static bool CompressEVEXImpl(MachineInstr &MI, const X86Subtarget &ST) {
252252
if (!performCustomAdjustments(MI, I->NewOpc))
253253
return false;
254254

255-
MI.setDesc(ST.getInstrInfo()->get(I->NewOpc));
256-
MI.setAsmPrinterFlag(X86::AC_EVEX_2_VEX);
255+
const MCInstrDesc &NewDesc = ST.getInstrInfo()->get(I->NewOpc);
256+
MI.setDesc(NewDesc);
257+
uint64_t Encoding = NewDesc.TSFlags & X86II::EncodingMask;
258+
auto AsmComment =
259+
(Encoding == X86II::VEX) ? X86::AC_EVEX_2_VEX : X86::AC_EVEX_2_LEGACY;
260+
MI.setAsmPrinterFlag(AsmComment);
257261
return true;
258262
}
259263

llvm/lib/Target/X86/X86InstrInfo.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class X86Subtarget;
2929
namespace X86 {
3030

3131
enum AsmComments {
32+
// For instr that was compressed from EVEX to LEGACY.
33+
AC_EVEX_2_LEGACY = MachineInstr::TAsmComments,
3234
// For instr that was compressed from EVEX to VEX.
33-
AC_EVEX_2_VEX = MachineInstr::TAsmComments
35+
AC_EVEX_2_VEX = AC_EVEX_2_LEGACY << 1
3436
};
3537

3638
/// Return a pair of condition code for the given predicate and whether

llvm/lib/Target/X86/X86MCInstLower.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,11 @@ void X86AsmPrinter::emitInstruction(const MachineInstr *MI) {
20552055
}
20562056
}
20572057

2058-
// Add a comment about EVEX-2-VEX compression for AVX-512 instrs that
2059-
// are compressed from EVEX encoding to VEX encoding.
2058+
// Add a comment about EVEX compression
20602059
if (TM.Options.MCOptions.ShowMCEncoding) {
2061-
if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_VEX)
2060+
if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_LEGACY)
2061+
OutStreamer->AddComment("EVEX TO LEGACY Compression ", false);
2062+
else if (MI->getAsmPrinterFlags() & X86::AC_EVEX_2_VEX)
20622063
OutStreamer->AddComment("EVEX TO VEX Compression ", false);
20632064
}
20642065

llvm/test/CodeGen/X86/crc32-intrinsics-fast-isel-x86.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ define i32 @test_mm_crc32_u8(i32 %a0, i32 %a1) nounwind {
2929
; EGPR-LABEL: test_mm_crc32_u8:
3030
; EGPR: # %bb.0:
3131
; EGPR-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
32-
; EGPR-NEXT: crc32b %sil, %eax # encoding: [0x62,0xf4,0x7c,0x08,0xf0,0xc6]
32+
; EGPR-NEXT: crc32b %sil, %eax # EVEX TO LEGACY Compression encoding: [0xf2,0x40,0x0f,0x38,0xf0,0xc6]
3333
; EGPR-NEXT: retq # encoding: [0xc3]
3434
%trunc = trunc i32 %a1 to i8
3535
%res = call i32 @llvm.x86.sse42.crc32.32.8(i32 %a0, i8 %trunc)
@@ -55,7 +55,7 @@ define i32 @test_mm_crc32_u16(i32 %a0, i32 %a1) nounwind {
5555
; EGPR-LABEL: test_mm_crc32_u16:
5656
; EGPR: # %bb.0:
5757
; EGPR-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
58-
; EGPR-NEXT: crc32w %si, %eax # encoding: [0x62,0xf4,0x7d,0x08,0xf1,0xc6]
58+
; EGPR-NEXT: crc32w %si, %eax # EVEX TO LEGACY Compression encoding: [0x66,0xf2,0x0f,0x38,0xf1,0xc6]
5959
; EGPR-NEXT: retq # encoding: [0xc3]
6060
%trunc = trunc i32 %a1 to i16
6161
%res = call i32 @llvm.x86.sse42.crc32.32.16(i32 %a0, i16 %trunc)
@@ -79,7 +79,7 @@ define i32 @test_mm_crc32_u32(i32 %a0, i32 %a1) nounwind {
7979
; EGPR-LABEL: test_mm_crc32_u32:
8080
; EGPR: # %bb.0:
8181
; EGPR-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
82-
; EGPR-NEXT: crc32l %esi, %eax # encoding: [0x62,0xf4,0x7c,0x08,0xf1,0xc6]
82+
; EGPR-NEXT: crc32l %esi, %eax # EVEX TO LEGACY Compression encoding: [0xf2,0x0f,0x38,0xf1,0xc6]
8383
; EGPR-NEXT: retq # encoding: [0xc3]
8484
%res = call i32 @llvm.x86.sse42.crc32.32.32(i32 %a0, i32 %a1)
8585
ret i32 %res

llvm/test/CodeGen/X86/crc32-intrinsics-fast-isel-x86_64.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define i64 @test_mm_crc64_u8(i64 %a0, i32 %a1) nounwind{
1515
;
1616
; EGPR-LABEL: test_mm_crc64_u8:
1717
; EGPR: # %bb.0:
18-
; EGPR-NEXT: crc32b %sil, %edi # encoding: [0x62,0xf4,0x7c,0x08,0xf0,0xfe]
18+
; EGPR-NEXT: crc32b %sil, %edi # EVEX TO LEGACY Compression encoding: [0xf2,0x40,0x0f,0x38,0xf0,0xfe]
1919
; EGPR-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
2020
; EGPR-NEXT: retq # encoding: [0xc3]
2121
%trunc = trunc i32 %a1 to i8
@@ -34,7 +34,7 @@ define i64 @test_mm_crc64_u64(i64 %a0, i64 %a1) nounwind{
3434
; EGPR-LABEL: test_mm_crc64_u64:
3535
; EGPR: # %bb.0:
3636
; EGPR-NEXT: movq %rdi, %rax # encoding: [0x48,0x89,0xf8]
37-
; EGPR-NEXT: crc32q %rsi, %rax # encoding: [0x62,0xf4,0xfc,0x08,0xf1,0xc6]
37+
; EGPR-NEXT: crc32q %rsi, %rax # EVEX TO LEGACY Compression encoding: [0xf2,0x48,0x0f,0x38,0xf1,0xc6]
3838
; EGPR-NEXT: retq # encoding: [0xc3]
3939
%res = call i64 @llvm.x86.sse42.crc32.64.64(i64 %a0, i64 %a1)
4040
ret i64 %res

llvm/test/CodeGen/X86/crc32-intrinsics-x86.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define i32 @crc32_32_8(i32 %a, i8 %b) nounwind {
1919
; EGPR-LABEL: crc32_32_8:
2020
; EGPR: ## %bb.0:
2121
; EGPR-NEXT: movl %edi, %eax ## encoding: [0x89,0xf8]
22-
; EGPR-NEXT: crc32b %sil, %eax ## encoding: [0x62,0xf4,0x7c,0x08,0xf0,0xc6]
22+
; EGPR-NEXT: crc32b %sil, %eax ## EVEX TO LEGACY Compression encoding: [0xf2,0x40,0x0f,0x38,0xf0,0xc6]
2323
; EGPR-NEXT: retq ## encoding: [0xc3]
2424
%tmp = call i32 @llvm.x86.sse42.crc32.32.8(i32 %a, i8 %b)
2525
ret i32 %tmp
@@ -42,7 +42,7 @@ define i32 @crc32_32_16(i32 %a, i16 %b) nounwind {
4242
; EGPR-LABEL: crc32_32_16:
4343
; EGPR: ## %bb.0:
4444
; EGPR-NEXT: movl %edi, %eax ## encoding: [0x89,0xf8]
45-
; EGPR-NEXT: crc32w %si, %eax ## encoding: [0x62,0xf4,0x7d,0x08,0xf1,0xc6]
45+
; EGPR-NEXT: crc32w %si, %eax ## EVEX TO LEGACY Compression encoding: [0x66,0xf2,0x0f,0x38,0xf1,0xc6]
4646
; EGPR-NEXT: retq ## encoding: [0xc3]
4747
%tmp = call i32 @llvm.x86.sse42.crc32.32.16(i32 %a, i16 %b)
4848
ret i32 %tmp
@@ -65,7 +65,7 @@ define i32 @crc32_32_32(i32 %a, i32 %b) nounwind {
6565
; EGPR-LABEL: crc32_32_32:
6666
; EGPR: ## %bb.0:
6767
; EGPR-NEXT: movl %edi, %eax ## encoding: [0x89,0xf8]
68-
; EGPR-NEXT: crc32l %esi, %eax ## encoding: [0x62,0xf4,0x7c,0x08,0xf1,0xc6]
68+
; EGPR-NEXT: crc32l %esi, %eax ## EVEX TO LEGACY Compression encoding: [0xf2,0x0f,0x38,0xf1,0xc6]
6969
; EGPR-NEXT: retq ## encoding: [0xc3]
7070
%tmp = call i32 @llvm.x86.sse42.crc32.32.32(i32 %a, i32 %b)
7171
ret i32 %tmp

llvm/test/CodeGen/X86/crc32-intrinsics-x86_64.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ define i64 @crc32_64_8(i64 %a, i8 %b) nounwind {
1515
; EGPR-LABEL: crc32_64_8:
1616
; EGPR: ## %bb.0:
1717
; EGPR-NEXT: movq %rdi, %rax ## encoding: [0x48,0x89,0xf8]
18-
; EGPR-NEXT: crc32b %sil, %eax ## encoding: [0x62,0xf4,0x7c,0x08,0xf0,0xc6]
18+
; EGPR-NEXT: crc32b %sil, %eax ## EVEX TO LEGACY Compression encoding: [0xf2,0x40,0x0f,0x38,0xf0,0xc6]
1919
; EGPR-NEXT: retq ## encoding: [0xc3]
2020
%tmp = call i64 @llvm.x86.sse42.crc32.64.8(i64 %a, i8 %b)
2121
ret i64 %tmp
@@ -31,7 +31,7 @@ define i64 @crc32_64_64(i64 %a, i64 %b) nounwind {
3131
; EGPR-LABEL: crc32_64_64:
3232
; EGPR: ## %bb.0:
3333
; EGPR-NEXT: movq %rdi, %rax ## encoding: [0x48,0x89,0xf8]
34-
; EGPR-NEXT: crc32q %rsi, %rax ## encoding: [0x62,0xf4,0xfc,0x08,0xf1,0xc6]
34+
; EGPR-NEXT: crc32q %rsi, %rax ## EVEX TO LEGACY Compression encoding: [0xf2,0x48,0x0f,0x38,0xf1,0xc6]
3535
; EGPR-NEXT: retq ## encoding: [0xc3]
3636
%tmp = call i64 @llvm.x86.sse42.crc32.64.64(i64 %a, i64 %b)
3737
ret i64 %tmp

llvm/test/CodeGen/X86/invpcid-intrinsic.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define void @test_invpcid(i32 %type, ptr %descriptor) {
2020
; EGPR-LABEL: test_invpcid:
2121
; EGPR: # %bb.0: # %entry
2222
; EGPR-NEXT: movl %edi, %eax # encoding: [0x89,0xf8]
23-
; EGPR-NEXT: invpcid (%rsi), %rax # encoding: [0x62,0xf4,0x7e,0x08,0xf2,0x06]
23+
; EGPR-NEXT: invpcid (%rsi), %rax # EVEX TO LEGACY Compression encoding: [0x66,0x0f,0x38,0x82,0x06]
2424
; EGPR-NEXT: retq # encoding: [0xc3]
2525
entry:
2626
call void @llvm.x86.invpcid(i32 %type, ptr %descriptor)
@@ -45,7 +45,7 @@ define void @test_invpcid2(ptr readonly %type, ptr %descriptor) {
4545
; EGPR-LABEL: test_invpcid2:
4646
; EGPR: # %bb.0: # %entry
4747
; EGPR-NEXT: movl (%rdi), %eax # encoding: [0x8b,0x07]
48-
; EGPR-NEXT: invpcid (%rsi), %rax # encoding: [0x62,0xf4,0x7e,0x08,0xf2,0x06]
48+
; EGPR-NEXT: invpcid (%rsi), %rax # EVEX TO LEGACY Compression encoding: [0x66,0x0f,0x38,0x82,0x06]
4949
; EGPR-NEXT: retq # encoding: [0xc3]
5050
entry:
5151
%0 = load i32, ptr %type, align 4

llvm/test/CodeGen/X86/movdir-intrinsic-x86.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ define void @test_movdiri(ptr %p, i32 %v) {
1818
;
1919
; EGPR-LABEL: test_movdiri:
2020
; EGPR: # %bb.0: # %entry
21-
; EGPR-NEXT: movdiri %esi, (%rdi) # encoding: [0x62,0xf4,0x7c,0x08,0xf9,0x37]
21+
; EGPR-NEXT: movdiri %esi, (%rdi) # EVEX TO LEGACY Compression encoding: [0x0f,0x38,0xf9,0x37]
2222
; EGPR-NEXT: retq # encoding: [0xc3]
2323
entry:
2424
call void @llvm.x86.directstore32(ptr %p, i32 %v)
@@ -42,7 +42,7 @@ define void @test_movdir64b(ptr %dst, ptr %src) {
4242
;
4343
; EGPR-LABEL: test_movdir64b:
4444
; EGPR: # %bb.0: # %entry
45-
; EGPR-NEXT: movdir64b (%rsi), %rdi # encoding: [0x62,0xf4,0x7d,0x08,0xf8,0x3e]
45+
; EGPR-NEXT: movdir64b (%rsi), %rdi # EVEX TO LEGACY Compression encoding: [0x66,0x0f,0x38,0xf8,0x3e]
4646
; EGPR-NEXT: retq # encoding: [0xc3]
4747
entry:
4848
call void @llvm.x86.movdir64b(ptr %dst, ptr %src)

llvm/test/CodeGen/X86/movdir-intrinsic-x86_64.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ define void @test_movdiri(ptr %p, i64 %v) {
1010
;
1111
; EGPR-LABEL: test_movdiri:
1212
; EGPR: # %bb.0: # %entry
13-
; EGPR-NEXT: movdiri %rsi, (%rdi) # encoding: [0x62,0xf4,0xfc,0x08,0xf9,0x37]
13+
; EGPR-NEXT: movdiri %rsi, (%rdi) # EVEX TO LEGACY Compression encoding: [0x48,0x0f,0x38,0xf9,0x37]
1414
; EGPR-NEXT: retq # encoding: [0xc3]
1515
entry:
1616
call void @llvm.x86.directstore64(ptr %p, i64 %v)

0 commit comments

Comments
 (0)