[PATCH] D12856: Always promote f16

Pirama Arumuga Nainar via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 11:44:38 PDT 2015


pirama created this revision.
pirama added reviewers: ab, olista01, srhines.
pirama added a subscriber: llvm-commits.
Herald added a subscriber: aemerson.

Bug: https://llvm.org/bugs/show_bug.cgi?id=24549

- Softening support of f16 was never finished, really.  Always promote
  f16 to f32.  If f32 is not legal, rely on f32 legalization after
  promotion.
- Update SoftenFloatRes_FP_EXTEND to look for a promoted operand if the
  operand's type action is to promote.
- Add the test case from the linked bug.

Ideally, we should test all the cases in
test/CodeGen/ARM/fp16-promote.ll with -vfp2.  Doing that needs extra
work:
- some functions in this test don't compile
- all the functions need a new set of CHECKs for when both f32 and f16
  are illegal.

http://reviews.llvm.org/D12856

Files:
  lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
  lib/CodeGen/TargetLoweringBase.cpp
  test/CodeGen/ARM/fp16-no-fpu.ll

Index: test/CodeGen/ARM/fp16-no-fpu.ll
===================================================================
--- /dev/null
+++ test/CodeGen/ARM/fp16-no-fpu.ll
@@ -0,0 +1,17 @@
+; RUN: llc -asm-verbose=false -mattr=-vfp2 < %s | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "armv7--none-eabi"
+
+; CHECK-LABEL: test_fadd:
+; CHECK: bl __gnu_h2f_ieee
+; CHECK: bl __gnu_h2f_ieee
+; CHECK: bl __aeabi_fadd
+; CHECK: bl __gnu_f2h_ieee
+define void @test_fadd(half* %p, half* %q) #0 {
+  %a = load half, half* %p, align 2
+  %b = load half, half* %q, align 2
+  %r = fadd half %a, %b
+  store half %r, half* %p
+  ret void
+}
Index: lib/CodeGen/TargetLoweringBase.cpp
===================================================================
--- lib/CodeGen/TargetLoweringBase.cpp
+++ lib/CodeGen/TargetLoweringBase.cpp
@@ -1280,19 +1280,12 @@
   }
 
   if (!isTypeLegal(MVT::f16)) {
-    // If the target has native f32 support, promote f16 operations to f32.  If
-    // f32 is not supported, generate soft float library calls.
-    if (isTypeLegal(MVT::f32)) {
-      NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
-      RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
-      TransformToType[MVT::f16] = MVT::f32;
-      ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
-    } else {
-      NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16];
-      RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16];
-      TransformToType[MVT::f16] = MVT::i16;
-      ValueTypeActions.setTypeAction(MVT::f16, TypeSoftenFloat);
-    }
+    // Promote f16 operations to f32.  For targets where f32 is not legal, the
+    // promoted value would then undergo f32 legalization.
+    NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::f32];
+    RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::f32];
+    TransformToType[MVT::f16] = MVT::f32;
+    ValueTypeActions.setTypeAction(MVT::f16, TypePromoteFloat);
   }
 
   // Loop over all of the vector value types to see which need transformations.
Index: lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -421,6 +421,8 @@
   RTLIB::Libcall LC = RTLIB::getFPEXT(Op.getValueType(), N->getValueType(0));
   if (getTypeAction(Op.getValueType()) == TargetLowering::TypeSoftenFloat)
     Op = GetSoftenedFloat(Op);
+  else if (getTypeAction(Op.getValueType()) == TargetLowering::TypePromoteFloat)
+    Op = GetPromotedFloat(Op);
   assert(LC != RTLIB::UNKNOWN_LIBCALL && "Unsupported FP_EXTEND!");
   return TLI.makeLibCall(DAG, LC, NVT, &Op, 1, false, SDLoc(N)).first;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12856.34717.patch
Type: text/x-patch
Size: 2772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150914/3ec85306/attachment.bin>


More information about the llvm-commits mailing list