[llvm] r313073 - [AArch64][GlobalISel] Select all fptruncs.
Ahmed Bougacha via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 14:04:10 PDT 2017
Author: ab
Date: Tue Sep 12 14:04:10 2017
New Revision: 313073
URL: http://llvm.org/viewvc/llvm-project?rev=313073&view=rev
Log:
[AArch64][GlobalISel] Select all fptruncs.
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.
Modified:
llvm/trunk/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir
Modified: llvm/trunk/include/llvm/Target/GlobalISel/SelectionDAGCompat.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/GlobalISel/SelectionDAGCompat.td?rev=313073&r1=313072&r2=313073&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GlobalISel/SelectionDAGCompat.td (original)
+++ llvm/trunk/include/llvm/Target/GlobalISel/SelectionDAGCompat.td Tue Sep 12 14:04:10 2017
@@ -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>;
Modified: llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp?rev=313073&r1=313072&r2=313073&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstructionSelector.cpp Tue Sep 12 14:04:10 2017
@@ -317,7 +317,9 @@ static bool selectCopy(MachineInstr &I,
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;
@@ -1203,33 +1205,6 @@ bool AArch64InstructionSelector::select(
constrainSelectedInstRegOperands(I, TII, TRI, RBI);
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: {
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir?rev=313073&r1=313072&r2=313073&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/select-fp-casts.mir Tue Sep 12 14:04:10 2017
@@ -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 }
@@ -28,8 +31,58 @@
...
---
-# 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
More information about the llvm-commits
mailing list