[AArch64][GlobalISel] Widen G_FPTO*I before clamping
authorJessica Paquette <jpaquette@apple.com>
Tue, 3 Aug 2021 23:42:22 +0000 (16:42 -0700)
committerJessica Paquette <jpaquette@apple.com>
Wed, 4 Aug 2021 17:19:26 +0000 (10:19 -0700)
Going through our legalization rules and doing some cleanup.

Widening and then clamping is usually easier than clamping and then widening.

This allows us to legalize some weird types like s88.

Differential Revision: https://reviews.llvm.org/D107413

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
llvm/test/CodeGen/AArch64/GlobalISel/legalize-fptoi.mir

index 2bd3889..279fdcf 100644 (file)
@@ -459,10 +459,10 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
   // Conversions
   getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI})
       .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
-      .clampScalar(0, s32, s64)
       .widenScalarToNextPow2(0)
-      .clampScalar(1, s32, s64)
-      .widenScalarToNextPow2(1);
+      .clampScalar(0, s32, s64)
+      .widenScalarToNextPow2(1)
+      .clampScalar(1, s32, s64);
 
   getActionDefinitionsBuilder({G_SITOFP, G_UITOFP})
       .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32})
index b2ee3a6..6b7b617 100644 (file)
@@ -266,3 +266,48 @@ body: |
     %1:_(s128) = G_FPTOSI %0
     $q0 = COPY %1
 ...
+---
+name:            test_fptosi_s88_s88
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK-LABEL: name: test_fptosi_s88_s88
+    ; CHECK: [[DEF:%[0-9]+]]:_(s88) = G_IMPLICIT_DEF
+    ; CHECK: [[FPTOSI:%[0-9]+]]:_(s128) = G_FPTOSI [[DEF]](s88)
+    ; CHECK: [[TRUNC:%[0-9]+]]:_(s88) = G_TRUNC [[FPTOSI]](s128)
+    ; CHECK: %trunc:_(s64) = G_TRUNC [[TRUNC]](s88)
+    ; CHECK: $x0 = COPY %trunc(s64)
+    %0:_(s88) = G_IMPLICIT_DEF
+    %1:_(s88) = G_FPTOSI %0
+    %trunc:_(s64) = G_TRUNC %1
+    $x0 = COPY %trunc
+...
+---
+name:            test_fptosi_s88_s64
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK-LABEL: name: test_fptosi_s88_s64
+    ; CHECK: [[DEF:%[0-9]+]]:_(s64) = G_IMPLICIT_DEF
+    ; CHECK: [[FPTOSI:%[0-9]+]]:_(s128) = G_FPTOSI [[DEF]](s64)
+    ; CHECK: [[TRUNC:%[0-9]+]]:_(s88) = G_TRUNC [[FPTOSI]](s128)
+    ; CHECK: %trunc:_(s64) = G_TRUNC [[TRUNC]](s88)
+    ; CHECK: $x0 = COPY %trunc(s64)
+    %0:_(s64) = G_IMPLICIT_DEF
+    %1:_(s88) = G_FPTOSI %0
+    %trunc:_(s64) = G_TRUNC %1
+    $x0 = COPY %trunc
+...
+---
+name:            test_fptosi_s64_s88
+body: |
+  bb.0:
+    liveins: $x0
+    ; CHECK-LABEL: name: test_fptosi_s64_s88
+    ; CHECK: [[DEF:%[0-9]+]]:_(s88) = G_IMPLICIT_DEF
+    ; CHECK: [[FPEXT:%[0-9]+]]:_(s128) = G_FPEXT [[DEF]](s88)
+    ; CHECK: [[FPTOSI:%[0-9]+]]:_(s64) = G_FPTOSI [[FPEXT]](s128)
+    ; CHECK: $x0 = COPY [[FPTOSI]](s64)
+    %0:_(s88) = G_IMPLICIT_DEF
+    %1:_(s64) = G_FPTOSI %0
+    $x0 = COPY %1