Skip to content

Commit 9497074

Browse files
atanasyantstellar
authored andcommitted
Merging r374544 and r374548:
------------------------------------------------------------------------ r374544 | atanasyan | 2019-10-11 05:33:12 -0700 (Fri, 11 Oct 2019) | 12 lines [mips] Fix loading "double" immediate into a GPR and FPR If a "double" (64-bit) value has zero low 32-bits, it's possible to load such value into a GP/FP registers as an instruction immediate. But now assembler loads only high 32-bits of the value. For example, if a target register is GPR the `li.d $4, 1.0` instruction converts into the `lui $4, 16368` one. As a result, we get `0x3FF00000` in the register. While a correct representation of the `1.0` value is `0x3FF0000000000000`. The patch fixes that. Differential Revision: https://reviews.llvm.org/D68776 ------------------------------------------------------------------------ ------------------------------------------------------------------------ r374548 | atanasyan | 2019-10-11 05:58:37 -0700 (Fri, 11 Oct 2019) | 1 line [mips] Follow-up to r374544. Fix test case. ------------------------------------------------------------------------
1 parent 7423211 commit 9497074

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,8 +3399,8 @@ bool MipsAsmParser::expandLoadDoubleImmToGPR(MCInst &Inst, SMLoc IDLoc,
33993399

34003400
if (LoImmOp64 == 0) {
34013401
if (isABI_N32() || isABI_N64()) {
3402-
if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister, false, true,
3403-
IDLoc, Out, STI))
3402+
if (loadImmediate(ImmOp64, FirstReg, Mips::NoRegister, false, true, IDLoc,
3403+
Out, STI))
34043404
return true;
34053405
} else {
34063406
if (loadImmediate(HiImmOp64, FirstReg, Mips::NoRegister, true, true,
@@ -3473,12 +3473,20 @@ bool MipsAsmParser::expandLoadDoubleImmToFPR(MCInst &Inst, bool Is64FPU,
34733473
!((HiImmOp64 & 0xffff0000) && (HiImmOp64 & 0x0000ffff))) {
34743474
// FIXME: In the case where the constant is zero, we can load the
34753475
// register directly from the zero register.
3476-
if (loadImmediate(HiImmOp64, TmpReg, Mips::NoRegister, true, true, IDLoc,
3476+
3477+
if (isABI_N32() || isABI_N64()) {
3478+
if (loadImmediate(ImmOp64, TmpReg, Mips::NoRegister, false, false, IDLoc,
3479+
Out, STI))
3480+
return true;
3481+
TOut.emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3482+
return false;
3483+
}
3484+
3485+
if (loadImmediate(HiImmOp64, TmpReg, Mips::NoRegister, true, false, IDLoc,
34773486
Out, STI))
34783487
return true;
3479-
if (isABI_N32() || isABI_N64())
3480-
TOut.emitRR(Mips::DMTC1, FirstReg, TmpReg, IDLoc, STI);
3481-
else if (hasMips32r2()) {
3488+
3489+
if (hasMips32r2()) {
34823490
TOut.emitRR(Mips::MTC1, FirstReg, Mips::ZERO, IDLoc, STI);
34833491
TOut.emitRRR(Mips::MTHC1_D32, FirstReg, FirstReg, TmpReg, IDLoc, STI);
34843492
} else {

llvm/test/MC/Mips/macro-li.d.s

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ li.d $4, 1.12345
4949
# N32-N64: ld $4, 0($1) # encoding: [0x00,0x00,0x24,0xdc]
5050

5151
li.d $4, 1
52-
# ALL: lui $4, 16368 # encoding: [0xf0,0x3f,0x04,0x3c]
53-
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
52+
# O32: lui $4, 16368 # encoding: [0xf0,0x3f,0x04,0x3c]
53+
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
54+
# N32-N64: ori $4, $zero, 65472 # encoding: [0xc0,0xff,0x04,0x34]
55+
# N32-N64: dsll $4, $4, 46 # encoding: [0xbc,0x23,0x04,0x00]
5456

5557
li.d $4, 1.0
56-
# ALL: lui $4, 16368 # encoding: [0xf0,0x3f,0x04,0x3c]
57-
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
58+
# O32: lui $4, 16368 # encoding: [0xf0,0x3f,0x04,0x3c]
59+
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
60+
# N32-N64: ori $4, $zero, 65472 # encoding: [0xc0,0xff,0x04,0x34]
61+
# N32-N64: dsll $4, $4, 46 # encoding: [0xbc,0x23,0x04,0x00]
5862

5963
li.d $4, 12345678910
6064
# ALL: .section .rodata,"a",@progbits
@@ -153,8 +157,10 @@ li.d $4, 0.4
153157
# N32-N64: ld $4, 0($1) # encoding: [0x00,0x00,0x24,0xdc]
154158

155159
li.d $4, 1.5
156-
# ALL: lui $4, 16376 # encoding: [0xf8,0x3f,0x04,0x3c]
157-
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
160+
# O32: lui $4, 16376 # encoding: [0xf8,0x3f,0x04,0x3c]
161+
# O32: addiu $5, $zero, 0 # encoding: [0x00,0x00,0x05,0x24]
162+
# N32-N64: ori $4, $zero, 65504 # encoding: [0xe0,0xff,0x04,0x34]
163+
# N32-N64: dsll $4, $4, 46 # encoding: [0xbc,0x23,0x04,0x00]
158164

159165
li.d $4, 12345678910.12345678910
160166
# ALL: .section .rodata,"a",@progbits
@@ -271,7 +277,8 @@ li.d $f4, 1
271277
# CHECK-MIPS32r2: lui $1, 16368 # encoding: [0xf0,0x3f,0x01,0x3c]
272278
# CHECK-MIPS32r2: mtc1 $zero, $f4 # encoding: [0x00,0x20,0x80,0x44]
273279
# CHECK-MIPS32r2: mthc1 $1, $f4 # encoding: [0x00,0x20,0xe1,0x44]
274-
# N32-N64: lui $1, 16368 # encoding: [0xf0,0x3f,0x01,0x3c]
280+
# N32-N64: ori $1, $zero, 65472 # encoding: [0xc0,0xff,0x01,0x34]
281+
# N32-N64: dsll $1, $1, 46 # encoding: [0xbc,0x0b,0x01,0x00]
275282
# N32-N64: dmtc1 $1, $f4 # encoding: [0x00,0x20,0xa1,0x44]
276283

277284
li.d $f4, 1.0
@@ -281,7 +288,8 @@ li.d $f4, 1.0
281288
# CHECK-MIPS32r2: lui $1, 16368 # encoding: [0xf0,0x3f,0x01,0x3c]
282289
# CHECK-MIPS32r2: mtc1 $zero, $f4 # encoding: [0x00,0x20,0x80,0x44]
283290
# CHECK-MIPS32r2: mthc1 $1, $f4 # encoding: [0x00,0x20,0xe1,0x44]
284-
# N32-N64: lui $1, 16368 # encoding: [0xf0,0x3f,0x01,0x3c]
291+
# N32-N64: ori $1, $zero, 65472 # encoding: [0xc0,0xff,0x01,0x34]
292+
# N32-N64: dsll $1, $1, 46 # encoding: [0xbc,0x0b,0x01,0x00]
285293
# N32-N64: dmtc1 $1, $f4 # encoding: [0x00,0x20,0xa1,0x44]
286294

287295
li.d $f4, 12345678910
@@ -360,7 +368,8 @@ li.d $f4, 1.5
360368
# CHECK-MIPS32r2: lui $1, 16376 # encoding: [0xf8,0x3f,0x01,0x3c]
361369
# CHECK-MIPS32r2: mtc1 $zero, $f4 # encoding: [0x00,0x20,0x80,0x44]
362370
# CHECK-MIPS32r2: mthc1 $1, $f4 # encoding: [0x00,0x20,0xe1,0x44]
363-
# N32-N64: lui $1, 16376 # encoding: [0xf8,0x3f,0x01,0x3c]
371+
# N32-N64: ori $1, $zero, 65504 # encoding: [0xe0,0xff,0x01,0x34]
372+
# N32-N64: dsll $1, $1, 46 # encoding: [0xbc,0x0b,0x01,0x00]
364373
# N32-N64: dmtc1 $1, $f4 # encoding: [0x00,0x20,0xa1,0x44]
365374

366375
li.d $f4, 2.5
@@ -370,7 +379,8 @@ li.d $f4, 2.5
370379
# CHECK-MIPS32r2: lui $1, 16388 # encoding: [0x04,0x40,0x01,0x3c]
371380
# CHECK-MIPS32r2: mtc1 $zero, $f4 # encoding: [0x00,0x20,0x80,0x44]
372381
# CHECK-MIPS32r2: mthc1 $1, $f4 # encoding: [0x00,0x20,0xe1,0x44]
373-
# N32-N64: lui $1, 16388 # encoding: [0x04,0x40,0x01,0x3c]
382+
# N32-N64: ori $1, $zero, 32776 # encoding: [0x08,0x80,0x01,0x34]
383+
# N32-N64: dsll $1, $1, 47 # encoding: [0xfc,0x0b,0x01,0x00]
374384
# N32-N64: dmtc1 $1, $f4 # encoding: [0x00,0x20,0xa1,0x44]
375385

376386
li.d $f4, 2.515625

0 commit comments

Comments
 (0)