From fa17ce8b6e73f845604ca15f12dbeea92f14e37a Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 23 Mar 2015 22:44:55 +0000 Subject: [PATCH] [SelectionDAG] Fixed issue with uitofp vector constant folding being treated as sitofp While the uitofp scalar constant folding treats an integer as an unsigned value (from lang ref): %X = sitofp i8 -1 to double ; yields double:-1.0 %Y = uitofp i8 -1 to double ; yields double:255.0 The vector constant folding was always using sitofp: %X = sitofp <2 x i8> to <2 x double> ; yields %Y = uitofp <2 x i8> to <2 x double> ; yields This patch fixes this so that the correct opcode is used for sitofp and uitofp. %X = sitofp <2 x i8> to <2 x double> ; yields %Y = uitofp <2 x i8> to <2 x double> ; yields Differential Revision: http://reviews.llvm.org/D8560 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233033 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 ++---- test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 9d22dbdcb27..eef07d92f6d 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2837,13 +2837,11 @@ SDValue SelectionDAG::getNode(unsigned Opcode, SDLoc DL, break; case ISD::UINT_TO_FP: case ISD::SINT_TO_FP: { + // Let the above scalar folding handle the folding of each element. SmallVector Ops; for (int i = 0, e = VT.getVectorNumElements(); i != e; ++i) { SDValue OpN = BV->getOperand(i); - // Let the above scalar folding handle the conversion of each - // element. - OpN = getNode(ISD::SINT_TO_FP, DL, VT.getVectorElementType(), - OpN); + OpN = getNode(Opcode, DL, VT.getVectorElementType(), OpN); Ops.push_back(OpN); } return getNode(ISD::BUILD_VECTOR, DL, VT, Ops); diff --git a/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll b/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll index 4317d8ab6a2..a2c5b3a6eed 100644 --- a/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll +++ b/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll @@ -72,3 +72,18 @@ define <4 x float> @foo3(<4 x float> %val, <4 x float> %test) nounwind { %result = sitofp <4 x i32> %and to <4 x float> ret <4 x float> %result } + +; Test the general purpose constant folding of uint->fp. +define void @foo4(<4 x float>* noalias %result) nounwind { +; CHECK-LABEL: LCPI4_0: +; CHECK-NEXT: .long 1065353216 ## float 1.000000e+00 +; CHECK-NEXT: .long 1123942400 ## float 1.270000e+02 +; CHECK-NEXT: .long 1124073472 ## float 1.280000e+02 +; CHECK-NEXT: .long 1132396544 ## float 2.550000e+02 +; CHECK-LABEL: foo4: +; CHECK: movaps LCPI4_0(%rip), %xmm0 + + %val = uitofp <4 x i8> to <4 x float> + store <4 x float> %val, <4 x float>* %result + ret void +}