[llvm] 5b094bf - [AArch64] Allow folding FMUL/FADD into FMA for FP16 types
Bradley Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 18 08:51:41 PST 2021
Author: Bradley Smith
Date: 2021-02-18T16:51:22Z
New Revision: 5b094bfeb3ccaf3ba118f161277ade9fc5147272
URL: https://github.com/llvm/llvm-project/commit/5b094bfeb3ccaf3ba118f161277ade9fc5147272
DIFF: https://github.com/llvm/llvm-project/commit/5b094bfeb3ccaf3ba118f161277ade9fc5147272.diff
LOG: [AArch64] Allow folding FMUL/FADD into FMA for FP16 types
isFMAFasterThanFMulAndFAdd should return true for FP16 types when
HasFullFP16 is present, since we have the instructions to handle it for
both SVE and NEON. (SVE patterns and tests will follow).
Differential Revision: https://reviews.llvm.org/D96599
Added:
Modified:
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/test/CodeGen/AArch64/f16-instructions.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index e77868cf868a..710c9d12a78a 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -11569,6 +11569,8 @@ bool AArch64TargetLowering::isFMAFasterThanFMulAndFAdd(
return false;
switch (VT.getSimpleVT().SimpleTy) {
+ case MVT::f16:
+ return Subtarget->hasFullFP16();
case MVT::f32:
case MVT::f64:
return true;
diff --git a/llvm/test/CodeGen/AArch64/f16-instructions.ll b/llvm/test/CodeGen/AArch64/f16-instructions.ll
index 6c1ea868a623..a324034f5b20 100644
--- a/llvm/test/CodeGen/AArch64/f16-instructions.ll
+++ b/llvm/test/CodeGen/AArch64/f16-instructions.ll
@@ -62,6 +62,26 @@ define half @test_fmul(half %a, half %b) #0 {
ret half %r
}
+; CHECK-CVT-LABEL: test_fmadd:
+; CHECK-CVT-NEXT: fcvt s1, h1
+; CHECK-CVT-NEXT: fcvt s0, h0
+; CHECK-CVT-NEXT: fmul s0, s0, s1
+; CHECK-CVT-NEXT: fcvt h0, s0
+; CHECK-CVT-NEXT: fcvt s0, h0
+; CHECK-CVT-NEXT: fcvt s1, h2
+; CHECK-CVT-NEXT: fadd s0, s0, s1
+; CHECK-CVT-NEXT: fcvt h0, s0
+; CHECK-CVT-NEXT: ret
+
+; CHECK-FP16-LABEL: test_fmadd:
+; CHECK-FP16-NEXT: fmadd h0, h0, h1, h2
+; CHECK-FP16-NEXT: ret
+
+define half @test_fmadd(half %a, half %b, half %c) #0 {
+ %mul = fmul fast half %a, %b
+ %r = fadd fast half %mul, %c
+ ret half %r
+}
; CHECK-CVT-LABEL: test_fdiv:
; CHECK-CVT-NEXT: fcvt s1, h1
; CHECK-CVT-NEXT: fcvt s0, h0
@@ -1305,8 +1325,7 @@ define half @test_round(half %a) #0 {
; CHECK-CVT-NEXT: ret
; CHECK-FP16-LABEL: test_fmuladd:
-; CHECK-FP16-NEXT: fmul h0, h0, h1
-; CHECK-FP16-NEXT: fadd h0, h0, h2
+; CHECK-FP16-NEXT: fmadd h0, h0, h1, h2
; CHECK-FP16-NEXT: ret
define half @test_fmuladd(half %a, half %b, half %c) #0 {
More information about the llvm-commits
mailing list