]> granicus.if.org Git - llvm/commitdiff
[AArch64][GlobalISel] Select all fptruncs.
authorAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 12 Sep 2017 21:04:10 +0000 (21:04 +0000)
committerAhmed Bougacha <ahmed.bougacha@gmail.com>
Tue, 12 Sep 2017 21:04:10 +0000 (21:04 +0000)
We already support these in tablegen, but we're matching the wrong
operator (libm ftrunc).  Fix that.

While there, drop the c++ code, support COPYs of FPR16, and add tests
for the other types.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313073 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/GlobalISel/SelectionDAGCompat.td
lib/Target/AArch64/AArch64InstructionSelector.cpp
test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir

index 9ff4313b55f6ca0b754b55d25aebc22cd8893db7..b7b9e73eaf6d63b017947c70e59ea64cef117d69 100644 (file)
@@ -51,7 +51,7 @@ def : GINodeEquiv<G_ASHR, sra>;
 def : GINodeEquiv<G_SELECT, select>;
 def : GINodeEquiv<G_FNEG, fneg>;
 def : GINodeEquiv<G_FPEXT, fpextend>;
-def : GINodeEquiv<G_FPTRUNC, ftrunc>;
+def : GINodeEquiv<G_FPTRUNC, fpround>;
 def : GINodeEquiv<G_FPTOSI, fp_to_sint>;
 def : GINodeEquiv<G_FPTOUI, fp_to_uint>;
 def : GINodeEquiv<G_SITOFP, sint_to_fp>;
index f91de078eb84b3a4b4690433aec16ada4d8d88e3..9cf9cd8b8e2d8878c609b97e253bb4660211a70a 100644 (file)
@@ -317,7 +317,9 @@ static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII,
   const TargetRegisterClass *RC = nullptr;
 
   if (RegBank.getID() == AArch64::FPRRegBankID) {
-    if (DstSize <= 32)
+    if (DstSize <= 16)
+      RC = &AArch64::FPR16RegClass;
+    else if (DstSize <= 32)
       RC = &AArch64::FPR32RegClass;
     else if (DstSize <= 64)
       RC = &AArch64::FPR64RegClass;
@@ -1205,33 +1207,6 @@ bool AArch64InstructionSelector::select(MachineInstr &I) const {
     return true;
   }
 
-  case TargetOpcode::G_FPTRUNC: {
-    if (MRI.getType(I.getOperand(0).getReg()) != LLT::scalar(32)) {
-      DEBUG(dbgs() << "G_FPTRUNC to type " << Ty
-                   << ", expected: " << LLT::scalar(32) << '\n');
-      return false;
-    }
-
-    if (MRI.getType(I.getOperand(1).getReg()) != LLT::scalar(64)) {
-      DEBUG(dbgs() << "G_FPTRUNC from type " << Ty
-                   << ", expected: " << LLT::scalar(64) << '\n');
-      return false;
-    }
-
-    const unsigned DefReg = I.getOperand(0).getReg();
-    const RegisterBank &RB = *RBI.getRegBank(DefReg, MRI, TRI);
-
-    if (RB.getID() != AArch64::FPRRegBankID) {
-      DEBUG(dbgs() << "G_FPTRUNC on bank: " << RB << ", expected: FPR\n");
-      return false;
-    }
-
-    I.setDesc(TII.get(AArch64::FCVTSDr));
-    constrainSelectedInstRegOperands(I, TII, TRI, RBI);
-
-    return true;
-  }
-
   case TargetOpcode::G_SELECT: {
     if (MRI.getType(I.getOperand(1).getReg()) != LLT::scalar(1)) {
       DEBUG(dbgs() << "G_SELECT cond has type: " << Ty
index 34c3da3a536945c266c7f88a3db8e8182c979f9e..d1a461107d8f24cc9dde6832998932d83c435a58 100644 (file)
@@ -3,7 +3,10 @@
 --- |
   target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
 
-  define void @fptrunc() { ret void }
+  define void @fptrunc_s16_s32_fpr() { ret void }
+  define void @fptrunc_s16_s64_fpr() { ret void }
+  define void @fptrunc_s32_s64_fpr() { ret void }
+
   define void @fpext() { ret void }
 
   define void @sitofp_s32_s32_fpr() { ret void }
 ...
 
 ---
-# CHECK-LABEL: name: fptrunc
-name:            fptrunc
+# CHECK-LABEL: name: fptrunc_s16_s32_fpr
+name:            fptrunc_s16_s32_fpr
+legalized:       true
+regBankSelected: true
+
+# CHECK:      registers:
+# CHECK: - { id: 0, class: fpr32, preferred-register: '' }
+# CHECK: - { id: 1, class: fpr16, preferred-register: '' }
+registers:
+  - { id: 0, class: fpr }
+  - { id: 1, class: fpr }
+
+# CHECK:  body:
+# CHECK:    %0 = COPY %s0
+# CHECK:    %1 = FCVTHSr %0
+body:             |
+  bb.0:
+    liveins: %s0
+
+    %0(s32) = COPY %s0
+    %1(s16) = G_FPTRUNC %0
+    %h0 = COPY %1(s16)
+...
+
+---
+# CHECK-LABEL: name: fptrunc_s16_s64_fpr
+name:            fptrunc_s16_s64_fpr
+legalized:       true
+regBankSelected: true
+
+# CHECK:      registers:
+# CHECK: - { id: 0, class: fpr64, preferred-register: '' }
+# CHECK: - { id: 1, class: fpr16, preferred-register: '' }
+registers:
+  - { id: 0, class: fpr }
+  - { id: 1, class: fpr }
+
+# CHECK:  body:
+# CHECK:    %0 = COPY %d0
+# CHECK:    %1 = FCVTHDr %0
+body:             |
+  bb.0:
+    liveins: %d0
+
+    %0(s64) = COPY %d0
+    %1(s16) = G_FPTRUNC %0
+    %h0 = COPY %1(s16)
+...
+
+---
+# CHECK-LABEL: name: fptrunc_s32_s64_fpr
+name:            fptrunc_s32_s64_fpr
 legalized:       true
 regBankSelected: true