Skip to content

Commit f1eccbe

Browse files
committed
[X86] Accept hasAVX512() as well as hasFMA() when generating FMA.
We don't always have FMA, for example when using 'clang -mavx512f' without an explicit CPU. Also check for an explicit +avx512f instead of CPUs in a couple related tests. llvm-svn: 240616
1 parent cee6d1b commit f1eccbe

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ X86TargetLowering::X86TargetLowering(const X86TargetMachine &TM,
11111111
setOperationAction(ISD::CTPOP, MVT::v8i32, Custom);
11121112
setOperationAction(ISD::CTPOP, MVT::v4i64, Custom);
11131113

1114-
if (Subtarget->hasFMA() || Subtarget->hasFMA4()) {
1114+
if (Subtarget->hasFMA() || Subtarget->hasFMA4() || Subtarget->hasAVX512()) {
11151115
setOperationAction(ISD::FMA, MVT::v8f32, Legal);
11161116
setOperationAction(ISD::FMA, MVT::v4f64, Legal);
11171117
setOperationAction(ISD::FMA, MVT::v4f32, Legal);
@@ -18636,7 +18636,7 @@ bool X86TargetLowering::isVectorLoadExtDesirable(SDValue) const { return true; }
1863618636

1863718637
bool
1863818638
X86TargetLowering::isFMAFasterThanFMulAndFAdd(EVT VT) const {
18639-
if (!(Subtarget->hasFMA() || Subtarget->hasFMA4()))
18639+
if (!(Subtarget->hasFMA() || Subtarget->hasFMA4() || Subtarget->hasAVX512()))
1864018640
return false;
1864118641

1864218642
VT = VT.getScalarType();
@@ -19821,6 +19821,7 @@ X86TargetLowering::emitEHSjLjLongJmp(MachineInstr *MI,
1982119821
// Replace 213-type (isel default) FMA3 instructions with 231-type for
1982219822
// accumulator loops. Writing back to the accumulator allows the coalescer
1982319823
// to remove extra copies in the loop.
19824+
// FIXME: Do this on AVX512. We don't support 231 variants yet (PR23937).
1982419825
MachineBasicBlock *
1982519826
X86TargetLowering::emitFMA3Instr(MachineInstr *MI,
1982619827
MachineBasicBlock *MBB) const {
@@ -24182,7 +24183,8 @@ static SDValue PerformFMACombine(SDNode *N, SelectionDAG &DAG,
2418224183

2418324184
EVT ScalarVT = VT.getScalarType();
2418424185
if ((ScalarVT != MVT::f32 && ScalarVT != MVT::f64) ||
24185-
(!Subtarget->hasFMA() && !Subtarget->hasFMA4()))
24186+
(!Subtarget->hasFMA() && !Subtarget->hasFMA4() &&
24187+
!Subtarget->hasAVX512()))
2418624188
return SDValue();
2418724189

2418824190
SDValue A = N->getOperand(0);

llvm/test/CodeGen/X86/avx512-fma-intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl --show-mc-encoding | FileCheck %s
1+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=+avx512f --show-mc-encoding | FileCheck %s
22

33
declare <16 x float> @llvm.x86.fma.mask.vfmadd.ps.512(<16 x float>, <16 x float>, <16 x float>, i16, i32)
44
declare <8 x double> @llvm.x86.fma.mask.vfmadd.pd.512(<8 x double>, <8 x double>, <8 x double>, i8, i32)

llvm/test/CodeGen/X86/avx512-fma.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=knl -fp-contract=fast | FileCheck %s
1+
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mattr=+avx512f -fp-contract=fast | FileCheck %s
22

33
; CHECK-LABEL: test_x86_fmadd_ps_z
44
; CHECK: vfmadd213ps %zmm2, %zmm1, %zmm0

llvm/test/CodeGen/X86/fma.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
; RUN: llc < %s -mtriple=i386-apple-darwin10 -mattr=-fma,-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-CALL
33
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -mattr=+fma,-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-INST
44
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -mattr=-fma,-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-CALL
5+
; RUN: llc < %s -mtriple=x86_64-apple-darwin10 -mattr=+avx512f,-fma,-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-INST
56
; RUN: llc < %s -march=x86 -mcpu=bdver2 -mattr=-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-INST
67
; RUN: llc < %s -march=x86 -mcpu=bdver2 -mattr=-fma,-fma4 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-FMA-CALL
78

0 commit comments

Comments
 (0)