mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
[AsmPrinter] Fix emission of non-standard integer constants for BE targets
The code assumed that zero-extending the integer constant to the designated alloc size would be fine even for BE targets, but that's not the case as that pulls in zeros from the MSB side while we actually expect the padding zeros to go after the LSB. I've changed the codepath handling the constant integers to use the store size for both small(er than u64) and big constants and then add zero padding right after that. Differential Revision: https://reviews.llvm.org/D78011
This commit is contained in:
parent
8056f1f6cb
commit
2362398441
@ -2617,9 +2617,10 @@ static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) {
|
||||
// [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);
|
||||
@ -2640,7 +2641,7 @@ static void emitGlobalConstantLargeInt(const ConstantInt *CI, AsmPrinter &AP) {
|
||||
// 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)))
|
||||
@ -2755,20 +2756,22 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
|
||||
return AP.OutStreamer->emitZeros(Size);
|
||||
|
||||
if (const ConstantInt *CI = dyn_cast<ConstantInt>(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<ConstantFP>(CV))
|
||||
|
@ -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
|
||||
|
@ -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 @@ define void @accessBig(i64* %storage) {
|
||||
store i82 %tmp, i82* %addr
|
||||
ret void
|
||||
}
|
||||
|
||||
@smallCst = internal constant i24 1122867
|
||||
|
@ -25,15 +25,15 @@ entry:
|
||||
;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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user