summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmed Bougacha <ahmed.bougacha@gmail.com>2017-01-20 01:37:24 +0000
committerAhmed Bougacha <ahmed.bougacha@gmail.com>2017-01-20 01:37:24 +0000
commitd294823930f4815eab824ae56ca7e6d9b1e8134c (patch)
tree6e4c0d4e89f24d446778672b68e28f10b149fad2
parent7eb7507aeb3552400c8a1f4dc82bb2212260c0da (diff)
downloadbcm5719-llvm-d294823930f4815eab824ae56ca7e6d9b1e8134c.tar.gz
bcm5719-llvm-d294823930f4815eab824ae56ca7e6d9b1e8134c.zip
[AArch64][GlobalISel] Widen scalar int->fp conversions.
It's incorrect to ignore the higher bits of the integer source. Teach the legalizer how to widen it. llvm-svn: 292563
-rw-r--r--llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp22
-rw-r--r--llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp8
-rw-r--r--llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir18
3 files changed, 41 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index 5f23d253f56..f77d807a69d 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -273,6 +273,28 @@ LegalizerHelper::widenScalar(MachineInstr &MI, unsigned TypeIdx, LLT WideTy) {
MI.eraseFromParent();
return Legalized;
}
+ case TargetOpcode::G_SITOFP:
+ case TargetOpcode::G_UITOFP: {
+ if (TypeIdx != 1)
+ return UnableToLegalize;
+
+ unsigned Src = MI.getOperand(1).getReg();
+ unsigned SrcExt = MRI.createGenericVirtualRegister(WideTy);
+
+ if (MI.getOpcode() == TargetOpcode::G_SITOFP) {
+ MIRBuilder.buildSExt(SrcExt, Src);
+ } else {
+ assert(MI.getOpcode() == TargetOpcode::G_UITOFP && "Unexpected conv op");
+ MIRBuilder.buildZExt(SrcExt, Src);
+ }
+
+ MIRBuilder.buildInstr(MI.getOpcode())
+ .addDef(MI.getOperand(0).getReg())
+ .addUse(SrcExt);
+
+ MI.eraseFromParent();
+ return Legalized;
+ }
case TargetOpcode::G_LOAD: {
assert(alignTo(MRI.getType(MI.getOperand(0).getReg()).getSizeInBits(), 8) ==
WideTy.getSizeInBits() &&
diff --git a/llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
index 48838f28b4b..dad390b752c 100644
--- a/llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64LegalizerInfo.cpp
@@ -141,12 +141,18 @@ AArch64LegalizerInfo::AArch64LegalizerInfo() {
setAction({G_TRUNC, 1, Ty}, Legal);
// Conversions
- for (auto Ty : { s1, s8, s16, s32, s64 }) {
+ for (auto Ty : { s32, s64 }) {
setAction({G_FPTOSI, 0, Ty}, Legal);
setAction({G_FPTOUI, 0, Ty}, Legal);
setAction({G_SITOFP, 1, Ty}, Legal);
setAction({G_UITOFP, 1, Ty}, Legal);
}
+ for (auto Ty : { s1, s8, s16 }) {
+ setAction({G_FPTOSI, 0, Ty}, Legal);
+ setAction({G_FPTOUI, 0, Ty}, Legal);
+ setAction({G_SITOFP, 1, Ty}, WidenScalar);
+ setAction({G_UITOFP, 1, Ty}, WidenScalar);
+ }
for (auto Ty : { s32, s64 }) {
setAction({G_FPTOSI, 1, Ty}, Legal);
diff --git a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir
index 176a7afefce..70ffc3ea3ac 100644
--- a/llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir
+++ b/llvm/test/CodeGen/AArch64/GlobalISel/legalize-itofp.mir
@@ -130,7 +130,8 @@ body: |
%1:_(s1) = G_TRUNC %0
; CHECK-LABEL: name: test_sitofp_s32_s1
- ; CHECK: %2(s32) = G_SITOFP %1
+ ; CHECK: %3(s32) = G_SEXT %1
+ ; CHECK: %2(s32) = G_SITOFP %3
%2:_(s32) = G_SITOFP %1
...
@@ -143,7 +144,8 @@ body: |
%1:_(s1) = G_TRUNC %0
; CHECK-LABEL: name: test_uitofp_s32_s1
- ; CHECK: %2(s32) = G_UITOFP %1
+ ; CHECK: %3(s32) = G_ZEXT %1
+ ; CHECK: %2(s32) = G_UITOFP %3
%2:_(s32) = G_UITOFP %1
...
@@ -156,7 +158,8 @@ body: |
%1:_(s8) = G_TRUNC %0
; CHECK-LABEL: name: test_sitofp_s64_s8
- ; CHECK: %2(s64) = G_SITOFP %1
+ ; CHECK: %3(s32) = G_SEXT %1
+ ; CHECK: %2(s64) = G_SITOFP %3
%2:_(s64) = G_SITOFP %1
...
@@ -169,7 +172,8 @@ body: |
%1:_(s8) = G_TRUNC %0
; CHECK-LABEL: name: test_uitofp_s64_s8
- ; CHECK: %2(s64) = G_UITOFP %1
+ ; CHECK: %3(s32) = G_ZEXT %1
+ ; CHECK: %2(s64) = G_UITOFP %3
%2:_(s64) = G_UITOFP %1
...
@@ -182,7 +186,8 @@ body: |
%1:_(s16) = G_TRUNC %0
; CHECK-LABEL: name: test_sitofp_s32_s16
- ; CHECK: %2(s32) = G_SITOFP %1
+ ; CHECK: %3(s32) = G_SEXT %1
+ ; CHECK: %2(s32) = G_SITOFP %3
%2:_(s32) = G_SITOFP %1
...
@@ -195,6 +200,7 @@ body: |
%1:_(s16) = G_TRUNC %0
; CHECK-LABEL: name: test_uitofp_s32_s16
- ; CHECK: %2(s32) = G_UITOFP %1
+ ; CHECK: %3(s32) = G_ZEXT %1
+ ; CHECK: %2(s32) = G_UITOFP %3
%2:_(s32) = G_UITOFP %1
...
OpenPOWER on IntegriCloud