From 3135ba9b381aa010a98c7a3b48c9d2338783d480 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Tue, 8 Dec 2015 02:37:48 +0000 Subject: [PATCH] AsmPrinter: Use emitGlobalConstantFP to emit elements of constant data It's strange to duplicate the logic for emitting FP values into emitGlobalConstantDataSequential, and it's even stranger that we end up printing the verbose assembly comments differently between the two paths. Just call into emitGlobalConstantFP rather than crudely duplicating its logic. llvm-svn: 254988 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 20 ++----- llvm/test/CodeGen/ARM/constants.ll | 6 +- llvm/test/CodeGen/Mips/sitofp-selectcc-opt.ll | 3 +- .../CodeGen/X86/copysign-constant-magnitude.ll | 24 ++++---- llvm/test/CodeGen/X86/fadd-combines.ll | 64 +++++++++++----------- llvm/test/CodeGen/X86/fmul-combines.ll | 40 +++++++------- llvm/test/CodeGen/X86/vec_uint_to_fp-fastmath.ll | 16 +++--- llvm/test/CodeGen/X86/vec_uint_to_fp.ll | 8 +-- .../CodeGen/X86/x86-setcc-int-to-fp-combine.ll | 16 +++--- 9 files changed, 92 insertions(+), 105 deletions(-) diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index b860424..f1f3547 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1873,6 +1873,8 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *C, const Constant *BaseCV = nullptr, uint64_t Offset = 0); +static void emitGlobalConstantFP(const ConstantFP *CFP, AsmPrinter &AP); + /// isRepeatedByteSequence - Determine whether the given value is /// composed of a repeated sequence of identical bytes and return the /// byte value. If it is not a repeated sequence, return -1. @@ -1951,22 +1953,8 @@ static void emitGlobalConstantDataSequential(const DataLayout &DL, ElementByteSize); } } else { - // FP Constants are printed as integer constants to avoid losing precision. - for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) { - APFloat Num = CDS->getElementAsAPFloat(I); - if (AP.isVerbose()) { - if (ElementByteSize == 4) - AP.OutStreamer->GetCommentOS() << "float " << Num.convertToFloat() - << '\n'; - else if (ElementByteSize == 8) - AP.OutStreamer->GetCommentOS() << "double " << Num.convertToDouble() - << '\n'; - else - llvm_unreachable("Unexpected float width"); - } - AP.OutStreamer->EmitIntValue(Num.bitcastToAPInt().getLimitedValue(), - ElementByteSize); - } + for (unsigned I = 0, E = CDS->getNumElements(); I != E; ++I) + emitGlobalConstantFP(cast(CDS->getElementAsConstant(I)), AP); } unsigned Size = DL.getTypeAllocSize(CDS->getType()); diff --git a/llvm/test/CodeGen/ARM/constants.ll b/llvm/test/CodeGen/ARM/constants.ll index 3baa103..75a90bb 100644 --- a/llvm/test/CodeGen/ARM/constants.ll +++ b/llvm/test/CodeGen/ARM/constants.ll @@ -63,7 +63,7 @@ define i32 @f8() nounwind { float 3.000000e+00> }, align 16 ; CHECK: const1 ; CHECK: .zero 16 -; CHECK: float 1.0 -; CHECK: float 2.0 -; CHECK: float 3.0 +; CHECK: float 1 +; CHECK: float 2 +; CHECK: float 3 ; CHECK: .zero 4 diff --git a/llvm/test/CodeGen/Mips/sitofp-selectcc-opt.ll b/llvm/test/CodeGen/Mips/sitofp-selectcc-opt.ll index c60fceb..751fba4 100644 --- a/llvm/test/CodeGen/Mips/sitofp-selectcc-opt.ll +++ b/llvm/test/CodeGen/Mips/sitofp-selectcc-opt.ll @@ -7,7 +7,7 @@ entry: ; check that this transformation doesn't happen: ; (sint_to_fp (setcc x, y, cc)) -> (select_cc x, y, -1.0, 0.0,, cc) ; -; CHECK-NOT: # double -1.000000e+00 +; CHECK-NOT: # double -1 %tobool1 = icmp ne i32 %a, 0 %not.tobool = icmp ne i64 %b, 0 @@ -19,4 +19,3 @@ entry: store double %add, double* @foo12.d4, align 8 ret double %add } - diff --git a/llvm/test/CodeGen/X86/copysign-constant-magnitude.ll b/llvm/test/CodeGen/X86/copysign-constant-magnitude.ll index 537d629..6c577a2 100644 --- a/llvm/test/CodeGen/X86/copysign-constant-magnitude.ll +++ b/llvm/test/CodeGen/X86/copysign-constant-magnitude.ll @@ -5,13 +5,13 @@ target triple = "x86_64-apple-macosx10.10.0" define void @test_copysign_const_magnitude_d(double %X) { ; CHECK: [[SIGNMASK:L.+]]: -; CHECK-NEXT: .quad -9223372036854775808 ## double -0.000000e+00 -; CHECK-NEXT: .quad 0 ## double 0.000000e+00 +; CHECK-NEXT: .quad -9223372036854775808 ## double -0 +; CHECK-NEXT: .quad 0 ## double 0 ; CHECK: [[ZERO:L.+]]: ; CHECK-NEXT: .space 16 ; CHECK: [[ONE:L.+]]: -; CHECK-NEXT: .quad 4607182418800017408 ## double 1.000000e+00 -; CHECK-NEXT: .quad 0 ## double 0.000000e+00 +; CHECK-NEXT: .quad 4607182418800017408 ## double 1 +; CHECK-NEXT: .quad 0 ## double 0 ; CHECK-LABEL: test_copysign_const_magnitude_d: ; CHECK: id @@ -50,17 +50,17 @@ define void @test_copysign_const_magnitude_d(double %X) { define void @test_copysign_const_magnitude_f(float %X) { ; CHECK: [[SIGNMASK:L.+]]: -; CHECK-NEXT: .long 2147483648 ## float -0.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 +; CHECK-NEXT: .long 2147483648 ## float -0 +; CHECK-NEXT: .long 0 ## float 0 +; CHECK-NEXT: .long 0 ## float 0 +; CHECK-NEXT: .long 0 ## float 0 ; CHECK: [[ZERO:L.+]]: ; CHECK-NEXT: .space 16 ; CHECK: [[ONE:L.+]]: -; CHECK-NEXT: .long 1065353216 ## float 1.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 -; CHECK-NEXT: .long 0 ## float 0.000000e+00 +; CHECK-NEXT: .long 1065353216 ## float 1 +; CHECK-NEXT: .long 0 ## float 0 +; CHECK-NEXT: .long 0 ## float 0 +; CHECK-NEXT: .long 0 ## float 0 ; CHECK-LABEL: test_copysign_const_magnitude_f: ; CHECK: id diff --git a/llvm/test/CodeGen/X86/fadd-combines.ll b/llvm/test/CodeGen/X86/fadd-combines.ll index 6b389f4..2df0e06 100644 --- a/llvm/test/CodeGen/X86/fadd-combines.ll +++ b/llvm/test/CodeGen/X86/fadd-combines.ll @@ -28,10 +28,10 @@ define float @fadd_2const_f32(float %x) #0 { ret float %z } -; CHECK: float 5.000000e+00 -; CHECK: float 5.000000e+00 -; CHECK: float 5.000000e+00 -; CHECK: float 5.000000e+00 +; CHECK: float 5 +; CHECK: float 5 +; CHECK: float 5 +; CHECK: float 5 define <4 x float> @fadd_2const_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_2const_4f32: ; CHECK: # BB#0: @@ -53,10 +53,10 @@ define float @fadd_x_fmul_x_c_f32(float %x) #0 { ret float %z } -; CHECK: float 2.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 5.000000e+00 +; CHECK: float 2 +; CHECK: float 3 +; CHECK: float 4 +; CHECK: float 5 define <4 x float> @fadd_x_fmul_x_c_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_x_fmul_x_c_4f32: ; CHECK: # BB#0: @@ -78,10 +78,10 @@ define float @fadd_fmul_x_c_x_f32(float %x) #0 { ret float %z } -; CHECK: float 2.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 5.000000e+00 +; CHECK: float 2 +; CHECK: float 3 +; CHECK: float 4 +; CHECK: float 5 define <4 x float> @fadd_fmul_x_c_x_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_fmul_x_c_x_4f32: ; CHECK: # BB#0: @@ -104,10 +104,10 @@ define float @fadd_fadd_x_x_fmul_x_c_f32(float %x) #0 { ret float %w } -; CHECK: float 3.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 5.000000e+00 -; CHECK: float 6.000000e+00 +; CHECK: float 3 +; CHECK: float 4 +; CHECK: float 5 +; CHECK: float 6 define <4 x float> @fadd_fadd_x_x_fmul_x_c_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_fadd_x_x_fmul_x_c_4f32: ; CHECK: # BB#0: @@ -131,10 +131,10 @@ define float @fadd_fmul_x_c_fadd_x_x_f32(float %x) #0 { ret float %w } -; CHECK: float 3.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 5.000000e+00 -; CHECK: float 6.000000e+00 +; CHECK: float 3 +; CHECK: float 4 +; CHECK: float 5 +; CHECK: float 6 define <4 x float> @fadd_fmul_x_c_fadd_x_x_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_fmul_x_c_fadd_x_x_4f32: ; CHECK: # BB#0: @@ -157,10 +157,10 @@ define float @fadd_x_fadd_x_x_f32(float %x) #0 { ret float %z } -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 +; CHECK: float 3 +; CHECK: float 3 +; CHECK: float 3 +; CHECK: float 3 define <4 x float> @fadd_x_fadd_x_x_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_x_fadd_x_x_4f32: ; CHECK: # BB#0: @@ -182,10 +182,10 @@ define float @fadd_fadd_x_x_x_f32(float %x) #0 { ret float %z } -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 -; CHECK: float 3.000000e+00 +; CHECK: float 3 +; CHECK: float 3 +; CHECK: float 3 +; CHECK: float 3 define <4 x float> @fadd_fadd_x_x_x_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_fadd_x_x_x_4f32: ; CHECK: # BB#0: @@ -207,10 +207,10 @@ define float @fadd_fadd_x_x_fadd_x_x_f32(float %x) #0 { ret float %z } -; CHECK: float 4.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 4.000000e+00 -; CHECK: float 4.000000e+00 +; CHECK: float 4 +; CHECK: float 4 +; CHECK: float 4 +; CHECK: float 4 define <4 x float> @fadd_fadd_x_x_fadd_x_x_4f32(<4 x float> %x) #0 { ; CHECK-LABEL: fadd_fadd_x_x_fadd_x_x_4f32: ; CHECK: # BB#0: diff --git a/llvm/test/CodeGen/X86/fmul-combines.ll b/llvm/test/CodeGen/X86/fmul-combines.ll index 42e5386..564ce42 100644 --- a/llvm/test/CodeGen/X86/fmul-combines.ll +++ b/llvm/test/CodeGen/X86/fmul-combines.ll @@ -56,10 +56,10 @@ define <4 x float> @fmul_c3_c4_v4f32(<4 x float> %x) #0 { } ; We should be able to pre-multiply the two constant vectors. -; CHECK: float 5.000000e+00 -; CHECK: float 1.200000e+01 -; CHECK: float 2.100000e+01 -; CHECK: float 3.200000e+01 +; CHECK: float 5 +; CHECK: float 12 +; CHECK: float 21 +; CHECK: float 32 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat: ; CHECK: mulps ; CHECK-NOT: mulps @@ -71,10 +71,10 @@ define <4 x float> @fmul_v4f32_two_consts_no_splat(<4 x float> %x) #0 { } ; Same as above, but reverse operands to make sure non-canonical form is also handled. -; CHECK: float 5.000000e+00 -; CHECK: float 1.200000e+01 -; CHECK: float 2.100000e+01 -; CHECK: float 3.200000e+01 +; CHECK: float 5 +; CHECK: float 12 +; CHECK: float 21 +; CHECK: float 32 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_non_canonical: ; CHECK: mulps ; CHECK-NOT: mulps @@ -87,10 +87,10 @@ define <4 x float> @fmul_v4f32_two_consts_no_splat_non_canonical(<4 x float> %x) ; More than one use of a constant multiply should not inhibit the optimization. ; Instead of a chain of 2 dependent mults, this test will have 2 independent mults. -; CHECK: float 6.000000e+00 -; CHECK: float 1.400000e+01 -; CHECK: float 2.400000e+01 -; CHECK: float 3.600000e+01 +; CHECK: float 6 +; CHECK: float 14 +; CHECK: float 24 +; CHECK: float 36 ; CHECK-LABEL: fmul_v4f32_two_consts_no_splat_multiple_use: ; CHECK: mulps ; CHECK: ret @@ -110,10 +110,10 @@ define <4 x float> @PR22698_splats(<4 x float> %a) #0 { %mul3 = fmul fast <4 x float> %a, %mul2 ret <4 x float> %mul3 -; CHECK: float 2.400000e+01 -; CHECK: float 2.400000e+01 -; CHECK: float 2.400000e+01 -; CHECK: float 2.400000e+01 +; CHECK: float 24 +; CHECK: float 24 +; CHECK: float 24 +; CHECK: float 24 ; CHECK-LABEL: PR22698_splats: ; CHECK: mulps ; CHECK: ret @@ -126,10 +126,10 @@ define <4 x float> @PR22698_no_splats(<4 x float> %a) #0 { %mul3 = fmul fast <4 x float> %a, %mul2 ret <4 x float> %mul3 -; CHECK: float 4.500000e+01 -; CHECK: float 1.200000e+02 -; CHECK: float 2.310000e+02 -; CHECK: float 3.840000e+02 +; CHECK: float 45 +; CHECK: float 120 +; CHECK: float 231 +; CHECK: float 384 ; CHECK-LABEL: PR22698_no_splats: ; CHECK: mulps ; CHECK: ret diff --git a/llvm/test/CodeGen/X86/vec_uint_to_fp-fastmath.ll b/llvm/test/CodeGen/X86/vec_uint_to_fp-fastmath.ll index 0d67ac4..1f36d06 100644 --- a/llvm/test/CodeGen/X86/vec_uint_to_fp-fastmath.ll +++ b/llvm/test/CodeGen/X86/vec_uint_to_fp-fastmath.ll @@ -14,10 +14,10 @@ ; CST-NEXT: .long 65535 # 0xffff ; CST: [[FPMASKCSTADDR:.LCPI[0-9_]+]]: -; CST-NEXT: .long 1199570944 # float 6.553600e+04 -; CST-NEXT: .long 1199570944 # float 6.553600e+04 -; CST-NEXT: .long 1199570944 # float 6.553600e+04 -; CST-NEXT: .long 1199570944 # float 6.553600e+04 +; CST-NEXT: .long 1199570944 # float 65536 +; CST-NEXT: .long 1199570944 # float 65536 +; CST-NEXT: .long 1199570944 # float 65536 +; CST-NEXT: .long 1199570944 # float 65536 ; AVX2: [[FPMASKCSTADDR:.LCPI[0-9_]+]]: ; AVX2-NEXT: .long 1199570944 # float 65536 @@ -69,10 +69,10 @@ define <4 x float> @test_uitofp_v4i32_to_v4f32(<4 x i32> %arg) { ; AVX-NEXT: .long 65535 # 0xffff ; AVX: [[FPMASKCSTADDR_v8:.LCPI[0-9_]+]]: -; AVX-NEXT: .long 1199570944 # float 6.553600e+04 -; AVX-NEXT: .long 1199570944 # float 6.553600e+04 -; AVX-NEXT: .long 1199570944 # float 6.553600e+04 -; AVX-NEXT: .long 1199570944 # float 6.553600e+04 +; AVX-NEXT: .long 1199570944 # float 65536 +; AVX-NEXT: .long 1199570944 # float 65536 +; AVX-NEXT: .long 1199570944 # float 65536 +; AVX-NEXT: .long 1199570944 # float 65536 ; AVX2: [[FPMASKCSTADDR_v8:.LCPI[0-9_]+]]: ; AVX2-NEXT: .long 1199570944 # float 65536 diff --git a/llvm/test/CodeGen/X86/vec_uint_to_fp.ll b/llvm/test/CodeGen/X86/vec_uint_to_fp.ll index 46cfcd9..ce0c11b 100644 --- a/llvm/test/CodeGen/X86/vec_uint_to_fp.ll +++ b/llvm/test/CodeGen/X86/vec_uint_to_fp.ll @@ -23,10 +23,10 @@ ; CST-NEXT: .long 1392508928 ## 0x53000000 ; CST: [[MAGICCSTADDR:LCPI0_[0-9]+]]: -; CST-NEXT: .long 3539992704 ## float -5.497642e+11 -; CST-NEXT: .long 3539992704 ## float -5.497642e+11 -; CST-NEXT: .long 3539992704 ## float -5.497642e+11 -; CST-NEXT: .long 3539992704 ## float -5.497642e+11 +; CST-NEXT: .long 3539992704 ## float -5.49764202E+11 +; CST-NEXT: .long 3539992704 ## float -5.49764202E+11 +; CST-NEXT: .long 3539992704 ## float -5.49764202E+11 +; CST-NEXT: .long 3539992704 ## float -5.49764202E+11 ; AVX2: [[LOWCSTADDR:LCPI0_[0-9]+]]: ; AVX2-NEXT: .long 1258291200 ## 0x4b000000 diff --git a/llvm/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll b/llvm/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll index 248a920..99b27ef 100644 --- a/llvm/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll +++ b/llvm/test/CodeGen/X86/x86-setcc-int-to-fp-combine.ll @@ -39,10 +39,10 @@ define void @foo1(<4 x float> %val, <4 x float> %test, <4 x double>* %p) nounwin ; Also test the general purpose constant folding of int->fp. define void @foo2(<4 x float>* noalias %result) nounwind { ; CHECK-LABEL: LCPI2_0: -; CHECK-NEXT: .long 1082130432 ## float 4.000000e+00 -; CHECK-NEXT: .long 1084227584 ## float 5.000000e+00 -; CHECK-NEXT: .long 1086324736 ## float 6.000000e+00 -; CHECK-NEXT: .long 1088421888 ## float 7.000000e+00 +; CHECK-NEXT: .long 1082130432 ## float 4 +; CHECK-NEXT: .long 1084227584 ## float 5 +; CHECK-NEXT: .long 1086324736 ## float 6 +; CHECK-NEXT: .long 1088421888 ## float 7 ; CHECK-LABEL: foo2: ; CHECK: movaps LCPI2_0(%rip), %xmm0 @@ -72,10 +72,10 @@ define <4 x float> @foo3(<4 x float> %val, <4 x float> %test) nounwind { ; 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-NEXT: .long 1065353216 ## float 1 +; CHECK-NEXT: .long 1123942400 ## float 127 +; CHECK-NEXT: .long 1124073472 ## float 128 +; CHECK-NEXT: .long 1132396544 ## float 255 ; CHECK-LABEL: foo4: ; CHECK: movaps LCPI4_0(%rip), %xmm0 -- 2.7.4