-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[X86][AMX] Support AMX-FP8 #113850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[X86][AMX] Support AMX-FP8 #113850
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /*===---------- amxfp8intrin.h - AMX intrinsics -*- C++ -*------------=== | ||
| * | ||
| * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| * See https://llvm.org/LICENSE.txt for license information. | ||
| * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| * | ||
| *===------------------------------------------------------------------------=== | ||
| */ | ||
|
|
||
| #ifndef __IMMINTRIN_H | ||
| #error "Never use <amxfp8intrin.h> directly; include <immintrin.h> instead." | ||
| #endif /* __IMMINTRIN_H */ | ||
|
|
||
| #ifndef __AMXFP8INTRIN_H | ||
| #define __AMXFP8INTRIN_H | ||
| #ifdef __x86_64__ | ||
|
|
||
| #define _tile_dpbf8ps __builtin_ia32_tdpbf8ps | ||
|
||
| #define _tile_dpbhf8ps __builtin_ia32_tdpbhf8ps | ||
| #define _tile_dphbf8ps __builtin_ia32_tdphbf8ps | ||
| #define _tile_dphf8ps __builtin_ia32_tdphf8ps | ||
|
||
|
|
||
| #endif /* __x86_64__ */ | ||
| #endif /* __AMXFP8INTRIN_H */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-fp8 \ | ||
| // RUN: -emit-llvm -o - -Werror -pedantic | FileCheck %s | ||
| #include <immintrin.h> | ||
|
|
||
| void test_amx(void *data) { | ||
| //CHECK-LABEL: @test_amx | ||
| //CHECK: call void @llvm.x86.tdpbf8ps(i8 1, i8 2, i8 3) | ||
| _tile_dpbf8ps(1, 2, 3); | ||
| } | ||
|
|
||
| void test_amx2(void *data) { | ||
| //CHECK-LABEL: @test_amx2 | ||
| //CHECK: call void @llvm.x86.tdpbhf8ps(i8 1, i8 2, i8 3) | ||
| _tile_dpbhf8ps(1, 2, 3); | ||
| } | ||
|
|
||
| void test_amx3(void *data) { | ||
| //CHECK-LABEL: @test_amx3 | ||
| //CHECK: call void @llvm.x86.tdphbf8ps(i8 1, i8 2, i8 3) | ||
| _tile_dphbf8ps(1, 2, 3); | ||
| } | ||
|
|
||
| void test_amx4(void *data) { | ||
| //CHECK-LABEL: @test_amx4 | ||
| //CHECK: call void @llvm.x86.tdphf8ps(i8 1, i8 2, i8 3) | ||
| _tile_dphf8ps(1, 2, 3); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-tile -target-feature +amx-fp8 -verify | ||
|
|
||
| #include <immintrin.h> | ||
|
|
||
| void test_amx(void *data) { | ||
| _tile_dpbf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
| _tile_dpbhf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
| _tile_dphbf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
| _tile_dphf8ps(4, 3, 3); // expected-error {{tile arguments must refer to different tiles}} | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // RUN: %clang_cc1 %s -ffreestanding -triple=x86_64-unknown-unknown -target-feature +amx-fp8 -emit-llvm -o - -Wall -Werror -pedantic | FileCheck %s | ||
|
|
||
| void f_tilemul(short a) | ||
| { | ||
| //CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdpbf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
| __asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
| "tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
| "tdpbf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
| "tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
| ::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
|
||
| //CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdpbhf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
| __asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
| "tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
| "tdpbhf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
| "tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
| ::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
|
||
| //CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdphbf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
| __asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
| "tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
| "tdphbf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
| "tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
| ::: "memory", "tmm0", "tmm6", "tmm7"); | ||
|
|
||
| //CHECK: call void asm sideeffect "tileloadd 0(%rsi,%r13,4), %tmm0 \0A\09tileloadd 0(%rdx,%r14,4), %tmm6 \0A\09tdphf8ps %tmm6, %tmm0, %tmm7 \0A\09tilestored %tmm7, 0(%r12,%r15,4) \0A\09", "~{memory},~{tmm0},~{tmm6},~{tmm7},~{dirflag},~{fpsr},~{flags}"() | ||
| __asm__ volatile ("tileloadd 0(%%rsi,%%r13,4), %%tmm0 \n\t" | ||
| "tileloadd 0(%%rdx,%%r14,4), %%tmm6 \n\t" | ||
| "tdphf8ps %%tmm6, %%tmm0, %%tmm7 \n\t" | ||
| "tilestored %%tmm7, 0(%%r12,%%r15,4) \n\t" | ||
| ::: "memory", "tmm0", "tmm6", "tmm7"); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5994,6 +5994,23 @@ let TargetPrefix = "x86" in { | |
| [llvm_i16_ty, llvm_i16_ty, llvm_i16_ty, | ||
| llvm_x86amx_ty, llvm_x86amx_ty, | ||
| llvm_x86amx_ty], []>; | ||
|
|
||
| def int_x86_tdpbf8ps : ClangBuiltin<"__builtin_ia32_tdpbf8ps">, | ||
| Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
| [ImmArg<ArgIndex<0>>, | ||
| ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
| def int_x86_tdpbhf8ps : ClangBuiltin<"__builtin_ia32_tdpbhf8ps">, | ||
| Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
| [ImmArg<ArgIndex<0>>, | ||
| ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
| def int_x86_tdphbf8ps : ClangBuiltin<"__builtin_ia32_tdphbf8ps">, | ||
| Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
| [ImmArg<ArgIndex<0>>, | ||
| ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
| def int_x86_tdphf8ps : ClangBuiltin<"__builtin_ia32_tdphf8ps">, | ||
| Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty], | ||
| [ImmArg<ArgIndex<0>>, | ||
| ImmArg<ArgIndex<1>>, ImmArg<ArgIndex<2>>]>; | ||
|
Comment on lines
+5997
to
+6013
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move them to line 5919. This is for internal intrinsics. |
||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,6 +270,9 @@ def FeatureAMXFP16 : SubtargetFeature<"amx-fp16", "HasAMXFP16", "true", | |
| def FeatureAMXCOMPLEX : SubtargetFeature<"amx-complex", "HasAMXCOMPLEX", "true", | ||
| "Support AMX-COMPLEX instructions", | ||
| [FeatureAMXTILE]>; | ||
| def FeatureAMXFP8 : SubtargetFeature<"amx-fp8", "HasAMXFP8", "true", | ||
| "Support AMX-FP8 instructions", | ||
| [FeatureAMXTILE]>; | ||
|
||
| def FeatureCMPCCXADD : SubtargetFeature<"cmpccxadd", "HasCMPCCXADD", "true", | ||
| "Support CMPCCXADD instructions">; | ||
| def FeatureRAOINT : SubtargetFeature<"raoint", "HasRAOINT", "true", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37503,6 +37503,38 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI, | |
| MI.eraseFromParent(); // The pseudo is gone now. | ||
| return BB; | ||
| } | ||
| case X86::PTDPBF8PS: | ||
| case X86::PTDPBHF8PS: | ||
| case X86::PTDPHBF8PS: | ||
| case X86::PTDPHF8PS: { | ||
|
||
| const DebugLoc &DL = MI.getDebugLoc(); | ||
| unsigned Opc; | ||
| switch (MI.getOpcode()) { | ||
| default: | ||
| llvm_unreachable("Unexpected instruction!"); | ||
| case X86::PTDPBF8PS: | ||
| Opc = X86::TDPBF8PS; | ||
| break; | ||
| case X86::PTDPBHF8PS: | ||
| Opc = X86::TDPBHF8PS; | ||
| break; | ||
| case X86::PTDPHBF8PS: | ||
| Opc = X86::TDPHBF8PS; | ||
| break; | ||
| case X86::PTDPHF8PS: | ||
| Opc = X86::TDPHF8PS; | ||
| break; | ||
| } | ||
|
|
||
| MachineInstrBuilder MIB = BuildMI(*BB, MI, DL, TII->get(Opc)); | ||
| MIB.addReg(TMMImmToTMMReg(MI.getOperand(0).getImm()), RegState::Define); | ||
| MIB.addReg(TMMImmToTMMReg(MI.getOperand(0).getImm()), RegState::Undef); | ||
| MIB.addReg(TMMImmToTMMReg(MI.getOperand(1).getImm()), RegState::Undef); | ||
| MIB.addReg(TMMImmToTMMReg(MI.getOperand(2).getImm()), RegState::Undef); | ||
|
|
||
| MI.eraseFromParent(); | ||
| return BB; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,3 +267,42 @@ let Predicates = [HasAMXCOMPLEX, In64BitMode] in { | |
| } | ||
| } // SchedRW = [WriteSystem] | ||
| } | ||
|
|
||
| // AMX-FP8 | ||
| let Predicates = [HasAMXFP8, In64BitMode] in { | ||
| let SchedRW = [WriteSystem] in { | ||
| let Constraints = "$src1 = $dst" in { | ||
| class AMX_FP8_BASE<bits<8> Opcode, string Opstr> : | ||
| I<Opcode, MRMSrcReg4VOp3, (outs TILE:$dst), | ||
| (ins TILE:$src1, TILE:$src2, TILE:$src3), | ||
| !strconcat(Opstr, "\t{$src3, $src2, $dst|$dst, $src2, $src3}"), | ||
| []>, VEX, VVVV; | ||
|
||
| } | ||
|
|
||
| def TDPBF8PS : AMX_FP8_BASE<0xfd, "tdpbf8ps">, T_MAP5, PS; | ||
| def TDPBHF8PS : AMX_FP8_BASE<0xfd, "tdpbhf8ps">, T_MAP5, XD; | ||
| def TDPHBF8PS : AMX_FP8_BASE<0xfd, "tdphbf8ps">, T_MAP5, XS; | ||
| def TDPHF8PS : AMX_FP8_BASE<0xfd, "tdphf8ps">, T_MAP5, PD; | ||
|
|
||
| let usesCustomInserter = 1 in { | ||
| // Pseudo instructions, using immediates instead of tile registers. | ||
| // To be translated to the actual instructions in X86ISelLowering.cpp | ||
| def PTDPBF8PS : PseudoI<(outs), (ins u8imm:$src1, | ||
| u8imm:$src2, u8imm:$src3), | ||
| [(int_x86_tdpbf8ps timm:$src1, | ||
| timm:$src2, timm:$src3)]>; | ||
| def PTDPBHF8PS : PseudoI<(outs), (ins u8imm:$src1, | ||
| u8imm:$src2, u8imm:$src3), | ||
| [(int_x86_tdpbhf8ps timm:$src1, | ||
| timm:$src2, timm:$src3)]>; | ||
| def PTDPHBF8PS : PseudoI<(outs), (ins u8imm:$src1, | ||
| u8imm:$src2, u8imm:$src3), | ||
| [(int_x86_tdphbf8ps timm:$src1, | ||
| timm:$src2, timm:$src3)]>; | ||
| def PTDPHF8PS : PseudoI<(outs), (ins u8imm:$src1, | ||
| u8imm:$src2, u8imm:$src3), | ||
| [(int_x86_tdphf8ps timm:$src1, | ||
| timm:$src2, timm:$src3)]>; | ||
|
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1876,6 +1876,10 @@ const StringMap<bool> sys::getHostCPUFeatures() { | |
| MaxLevel >= 0x19 && !getX86CpuIDAndInfo(0x19, &EAX, &EBX, &ECX, &EDX); | ||
| Features["widekl"] = HasLeaf7 && HasLeaf19 && ((EBX >> 2) & 1); | ||
|
|
||
| bool HasLeaf1E = | ||
| MaxLevel >= 0x1e && !getX86CpuIDAndInfo(0x1e, &EAX, &EBX, &ECX, &EDX); | ||
|
||
| Features["amx-fp8"] = HasLeaf1E && ((EAX >> 4) & 1) && HasAMXSave; | ||
|
|
||
| bool HasLeaf24 = | ||
| MaxLevel >= 0x24 && !getX86CpuIDAndInfo(0x24, &EAX, &EBX, &ECX, &EDX); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| ; RUN: llc < %s -O0 -mtriple=x86_64-unknown-unknown -mattr=+amx-tile,+amx-fp8 | FileCheck %s | ||
|
|
||
| ; CHECK-LABEL: test_amx: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK: tdpbf8ps %tmm3, %tmm2, %tmm1 | ||
| ; CHECK: tdpbhf8ps %tmm3, %tmm2, %tmm1 | ||
| ; CHECK: tdphbf8ps %tmm3, %tmm2, %tmm1 | ||
| ; CHECK: tdphf8ps %tmm3, %tmm2, %tmm1 | ||
|
|
||
| define void @test_amx(){ | ||
| call void @llvm.x86.tdpbf8ps(i8 1, i8 2, i8 3) | ||
| call void @llvm.x86.tdpbhf8ps(i8 1, i8 2, i8 3) | ||
| call void @llvm.x86.tdphbf8ps(i8 1, i8 2, i8 3) | ||
| call void @llvm.x86.tdphf8ps(i8 1, i8 2, i8 3) | ||
| ret void | ||
| } | ||
| declare void @llvm.x86.tdpbf8ps(i8 %tile0, i8 %tile1, i8 %tile2) | ||
| declare void @llvm.x86.tdpbhf8ps(i8 %tile0, i8 %tile1, i8 %tile2) | ||
| declare void @llvm.x86.tdphbf8ps(i8 %tile0, i8 %tile1, i8 %tile2) | ||
| declare void @llvm.x86.tdphf8ps(i8 %tile0, i8 %tile1, i8 %tile2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it aligned to 80 column.