Index: lib/Target/PowerPC/PPCISelLowering.cpp =================================================================== --- lib/Target/PowerPC/PPCISelLowering.cpp +++ lib/Target/PowerPC/PPCISelLowering.cpp @@ -6609,11 +6609,17 @@ /// \brief Analyze profitability of direct move /// prefer float load to int load plus direct move /// when there is no integer use of int load -static bool directMoveIsProfitable(const SDValue &Op) { +static bool directMoveIsProfitable(const SDValue &Op, int cpu) { SDNode *Origin = Op.getOperand(0).getNode(); if (Origin->getOpcode() != ISD::LOAD) return true; + // Power8 has MTVSRWZ but no LXSIBZX/LXSIHZX, + // so prefer direct move if the memory size is 1 or 2 bytes. + MachineMemOperand *MMO = cast(Origin)->getMemOperand(); + if (cpu == PPC::DIR_PWR8 && MMO->getSize() <= 2) + return true; + for (SDNode::use_iterator UI = Origin->use_begin(), UE = Origin->use_end(); UI != UE; ++UI) { @@ -6698,7 +6704,8 @@ // If we have direct moves, we can do all the conversion, skip the store/load // however, without FPCVT we can't do most conversions. - if (Subtarget.hasDirectMove() && directMoveIsProfitable(Op) && + if (Subtarget.hasDirectMove() && + directMoveIsProfitable(Op, Subtarget.getDarwinDirective()) && Subtarget.isPPC64() && Subtarget.hasFPCVT()) return LowerINT_TO_FPDirectMove(Op, DAG, dl); Index: test/CodeGen/PowerPC/pr31144.ll =================================================================== --- test/CodeGen/PowerPC/pr31144.ll +++ test/CodeGen/PowerPC/pr31144.ll @@ -0,0 +1,28 @@ +; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 -mattr=+vsx < %s | FileCheck %s + +declare void @bar(double) + +define void @foo1(i8* %p) { +entry: + %0 = load i8, i8* %p, align 1 + %conv = uitofp i8 %0 to double + call void @bar(double %conv) + ret void + +; CHECK-LABEL: @foo1 +; CHECK: mtvsrwz +; CHECK-NOT: lxsiwzx +} + +define void @foo2(i16* %p) { +entry: + %0 = load i16, i16* %p, align 2 + %conv = uitofp i16 %0 to double + call void @bar(double %conv) + ret void + +; CHECK-LABEL: @foo2 +; CHECK: mtvsrwz +; CHECK-NOT: lxsiwzx +} +