[llvm] r292828 - [AArch64][GlobalISel] Legalize narrow scalar fp->int conversions.

Ahmed Bougacha via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 13:10:14 PST 2017


Author: ab
Date: Mon Jan 23 15:10:14 2017
New Revision: 292828

URL: http://llvm.org/viewvc/llvm-project?rev=292828&view=rev
Log:
[AArch64][GlobalISel] Legalize narrow scalar fp->int conversions.

Since we're now avoiding operations using narrow scalar integer types,
we have to legalize the integer side of the FP conversions.

This requires teaching the legalizer how to do that.

Modified:
    llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
    llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
    llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir

Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=292828&r1=292827&r2=292828&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Mon Jan 23 15:10:14 2017
@@ -273,6 +273,20 @@ LegalizerHelper::widenScalar(MachineInst
     MI.eraseFromParent();
     return Legalized;
   }
+  case TargetOpcode::G_FPTOSI:
+  case TargetOpcode::G_FPTOUI: {
+    if (TypeIdx != 0)
+      return UnableToLegalize;
+
+    unsigned DstExt = MRI.createGenericVirtualRegister(WideTy);
+    MIRBuilder.buildInstr(MI.getOpcode())
+        .addDef(DstExt)
+        .addUse(MI.getOperand(1).getReg());
+
+    MIRBuilder.buildTrunc(MI.getOperand(0).getReg(), DstExt);
+    MI.eraseFromParent();
+    return Legalized;
+  }
   case TargetOpcode::G_SITOFP:
   case TargetOpcode::G_UITOFP: {
     if (TypeIdx != 1)

Modified: llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp?rev=292828&r1=292827&r2=292828&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64LegalizerInfo.cpp Mon Jan 23 15:10:14 2017
@@ -151,9 +151,8 @@ AArch64LegalizerInfo::AArch64LegalizerIn
     setAction({G_UITOFP, 1, Ty}, Legal);
   }
   for (auto Ty : { s1, s8, s16 }) {
-    // FIXME: These should be widened on types smaller than s32.
-    setAction({G_FPTOSI, 0, Ty}, Legal);
-    setAction({G_FPTOUI, 0, Ty}, Legal);
+    setAction({G_FPTOSI, 0, Ty}, WidenScalar);
+    setAction({G_FPTOUI, 0, Ty}, WidenScalar);
     setAction({G_SITOFP, 1, Ty}, WidenScalar);
     setAction({G_UITOFP, 1, Ty}, WidenScalar);
   }

Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir?rev=292828&r1=292827&r2=292828&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir Mon Jan 23 15:10:14 2017
@@ -130,7 +130,8 @@ body: |
     %0:_(s32) = COPY %w0
 
     ; CHECK-LABEL: name: test_fptosi_s1_s32
-    ; CHECK: %1(s1) = G_FPTOSI %0
+    ; CHECK: %2(s32) = G_FPTOSI %0
+    ; CHECK: %1(s1) = G_TRUNC %2
     %1:_(s1) = G_FPTOSI %0
 ...
 
@@ -142,7 +143,8 @@ body: |
     %0:_(s32) = COPY %w0
 
     ; CHECK-LABEL: name: test_fptoui_s1_s32
-    ; CHECK: %1(s1) = G_FPTOUI %0
+    ; CHECK: %2(s32) = G_FPTOUI %0
+    ; CHECK: %1(s1) = G_TRUNC %2
     %1:_(s1) = G_FPTOUI %0
 ...
 
@@ -154,7 +156,8 @@ body: |
     %0:_(s64) = COPY %x0
 
     ; CHECK-LABEL: name: test_fptosi_s8_s64
-    ; CHECK: %1(s8) = G_FPTOSI %0
+    ; CHECK: %2(s32) = G_FPTOSI %0
+    ; CHECK: %1(s8) = G_TRUNC %2
     %1:_(s8) = G_FPTOSI %0
 ...
 
@@ -166,7 +169,8 @@ body: |
     %0:_(s64) = COPY %x0
 
     ; CHECK-LABEL: name: test_fptoui_s8_s64
-    ; CHECK: %1(s8) = G_FPTOUI %0
+    ; CHECK: %2(s32) = G_FPTOUI %0
+    ; CHECK: %1(s8) = G_TRUNC %2
     %1:_(s8) = G_FPTOUI %0
 ...
 
@@ -178,7 +182,8 @@ body: |
     %0:_(s32) = COPY %w0
 
     ; CHECK-LABEL: name: test_fptosi_s16_s32
-    ; CHECK: %1(s16) = G_FPTOSI %0
+    ; CHECK: %2(s32) = G_FPTOSI %0
+    ; CHECK: %1(s16) = G_TRUNC %2
     %1:_(s16) = G_FPTOSI %0
 ...
 
@@ -190,6 +195,7 @@ body: |
     %0:_(s32) = COPY %w0
 
     ; CHECK-LABEL: name: test_fptoui_s16_s32
-    ; CHECK: %1(s16) = G_FPTOUI %0
+    ; CHECK: %2(s32) = G_FPTOUI %0
+    ; CHECK: %1(s16) = G_TRUNC %2
     %1:_(s16) = G_FPTOUI %0
 ...




More information about the llvm-commits mailing list