Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -2611,9 +2611,10 @@ // [chunk1][chunk2] ... [chunkN]. // The most significant chunk is chunkN and it should be emitted first. // However, due to the alignment issue chunkN contains useless bits. - // Realign the chunks so that they contain only useless information: + // Realign the chunks so that they contain only useful information: // ExtraBits 0 1 (BitWidth / 64) - 1 // chu[nk1 chu][nk2 chu] ... [nkN-1 chunkN] + ExtraBitsSize = alignTo(ExtraBitsSize, 8); ExtraBits = Realigned.getRawData()[0] & (((uint64_t)-1) >> (64 - ExtraBitsSize)); Realigned.lshrInPlace(ExtraBitsSize); @@ -2634,7 +2635,7 @@ // Emit the extra bits after the 64-bits chunks. // Emit a directive that fills the expected size. - uint64_t Size = AP.getDataLayout().getTypeAllocSize(CI->getType()); + uint64_t Size = AP.getDataLayout().getTypeStoreSize(CI->getType()); Size -= (BitWidth / 64) * 8; assert(Size && Size * 8 >= ExtraBitsSize && (ExtraBits & (((uint64_t)-1) >> (64 - ExtraBitsSize))) @@ -2749,20 +2750,22 @@ return AP.OutStreamer->emitZeros(Size); if (const ConstantInt *CI = dyn_cast(CV)) { - switch (Size) { - case 1: - case 2: - case 4: - case 8: + const uint64_t StoreSize = DL.getTypeStoreSize(CV->getType()); + + if (StoreSize < 8) { if (AP.isVerbose()) AP.OutStreamer->GetCommentOS() << format("0x%" PRIx64 "\n", CI->getZExtValue()); - AP.OutStreamer->emitIntValue(CI->getZExtValue(), Size); - return; - default: + AP.OutStreamer->emitIntValue(CI->getZExtValue(), StoreSize); + } else { emitGlobalConstantLargeInt(CI, AP); - return; } + + // Emit tail padding if needed + if (Size != StoreSize) + AP.OutStreamer->emitZeros(Size - StoreSize); + + return; } if (const ConstantFP *CFP = dyn_cast(CV)) Index: llvm/test/CodeGen/ARM/emit-big-cst.ll =================================================================== --- llvm/test/CodeGen/ARM/emit-big-cst.ll +++ llvm/test/CodeGen/ARM/emit-big-cst.ll @@ -4,7 +4,9 @@ ; CHECK: bigCst: ; CHECK-NEXT: .long 1694510592 ; CHECK-NEXT: .long 2960197 -; CHECK-NEXT: .long 26220 +; CHECK-NEXT: .short 26220 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .zero 1 ; CHECK-NEXT: .size bigCst, 12 @bigCst = internal constant i82 483673642326615442599424 Index: llvm/test/CodeGen/Mips/emit-big-cst.ll =================================================================== --- llvm/test/CodeGen/Mips/emit-big-cst.ll +++ llvm/test/CodeGen/Mips/emit-big-cst.ll @@ -1,10 +1,32 @@ -; RUN: llc -march=mips < %s | FileCheck %s +; RUN: llc -march=mips < %s | FileCheck %s --check-prefix=BE +; RUN: llc -march=mipsel < %s | FileCheck %s --check-prefix=LE ; Check assembly printing of odd constants. -; CHECK: bigCst: -; CHECK-NEXT: .8byte 1845068520838224192 -; CHECK-NEXT: .8byte 11776 -; CHECK-NEXT: .size bigCst, 16 +; BE-LABEL: bigCst: +; BE-NEXT: .8byte 28829195638097253 +; BE-NEXT: .2byte 46 +; BE-NEXT: .byte 0 +; BE-NEXT: .space 5 +; BE-NEXT: .size bigCst, 16 + +; LE-LABEL: bigCst: +; LE-NEXT: .8byte 12713950999227904 +; LE-NEXT: .2byte 26220 +; LE-NEXT: .byte 0 +; LE-NEXT: .space 5 +; LE-NEXT: .size bigCst, 16 + +; BE-LABEL: smallCst: +; BE-NEXT: .2byte 4386 +; BE-NEXT: .byte 51 +; BE-NEXT: .space 1 +; BE-NEXT: .size smallCst, 4 + +; LE-LABEL: smallCst: +; LE-NEXT: .2byte 8755 +; LE-NEXT: .byte 17 +; LE-NEXT: .space 1 +; LE-NEXT: .size smallCst, 4 @bigCst = internal constant i82 483673642326615442599424 @@ -15,3 +37,5 @@ store i82 %tmp, i82* %addr ret void } + +@smallCst = internal constant i24 1122867 Index: llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll =================================================================== --- llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll +++ llvm/test/CodeGen/PowerPC/aix-xcoff-mergeable-const.ll @@ -25,15 +25,15 @@ ;CHECK: .csect .rodata[RO] ;CHECK-NEXT: .align 4 ;CHECK-NEXT: .L__const.main.cnst32: -;CHECK-NEXT: .llong 4611686018427387954 # 0x4000000000000032 +;CHECK-NEXT: .llong 4611686018427387954 ;CHECK-NEXT: .long 0 # 0x0 ;CHECK-NEXT: .space 4 -;CHECK-NEXT: .llong 0 # 0x0 +;CHECK-NEXT: .llong 0 ;CHECK-NEXT: .long 0 # 0x0 ;CHECK-NEXT: .space 4 ;CHECK-NEXT: .align 3 ;CHECK-NEXT: .L__const.main.cnst16: -;CHECK-NEXT: .llong 4611686018427387926 # 0x4000000000000016 +;CHECK-NEXT: .llong 4611686018427387926 ;CHECK-NEXT: .long 0 # 0x0 ;CHECK-NEXT: .space 4 ;CHECK-NEXT: .align 3 Index: llvm/test/CodeGen/X86/emit-big-cst.ll =================================================================== --- llvm/test/CodeGen/X86/emit-big-cst.ll +++ llvm/test/CodeGen/X86/emit-big-cst.ll @@ -3,7 +3,9 @@ ; CHECK: bigCst: ; CHECK-NEXT: .quad 12713950999227904 -; CHECK-NEXT: .quad 26220 +; CHECK-NEXT: .short 26220 +; CHECK-NEXT: .byte 0 +; CHECK-NEXT: .zero 5 ; CHECK-NEXT: .size bigCst, 16 @bigCst = internal constant i82 483673642326615442599424 Index: llvm/test/CodeGen/X86/global-fill.ll =================================================================== --- llvm/test/CodeGen/X86/global-fill.ll +++ llvm/test/CodeGen/X86/global-fill.ll @@ -2,8 +2,12 @@ @test1 = global [2 x i24] [i24 -1, i24 -1] ; CHECK-LABEL: test1: -; CHECK-NEXT: .long 16777215 -; CHECK-NEXT: .long 16777215 +; CHECK-NEXT: .short 65535 +; CHECK-NEXT: .byte 255 +; CHECK-NEXT: .space 1 +; CHECK-NEXT: .short 65535 +; CHECK-NEXT: .byte 255 +; CHECK-NEXT: .space 1 @test2 = global [2 x i7] [i7 1, i7 1] ; CHECK-LABEL: test2: