Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -1731,7 +1731,8 @@ tmpInst.addOperand(MCOperand::CreateReg(Mips::ZERO)); tmpInst.addOperand(MCOperand::CreateImm(ImmValue)); Instructions.push_back(tmpInst); - } else if ((ImmValue & 0xffffffff) == ImmValue) { + } else if ((ImmValue & 0xffffffff) == ImmValue || + (ImmValue | ~0x7fffffff) == ImmValue) { // For all other values which are representable as a 32-bit integer: // li d,j => lui d,hi16(j) // ori d,d,lo16(j) Index: test/MC/Mips/mips-expansions.s =================================================================== --- test/MC/Mips/mips-expansions.s +++ test/MC/Mips/mips-expansions.s @@ -9,6 +9,8 @@ # CHECK: lui $7, 1 # encoding: [0x01,0x00,0x07,0x3c] # CHECK: ori $7, $7, 2 # encoding: [0x02,0x00,0xe7,0x34] # CHECK: addiu $8, $zero, -8 # encoding: [0xf8,0xff,0x08,0x24] +# CHECK: lui $10, 65519 # encoding: [0xef,0xff,0x0a,0x3c] +# CHECK: ori $10, $10, 61423 # encoding: [0xef,0xef,0x4a,0x35] # CHECK: addiu $4, $zero, 20 # encoding: [0x14,0x00,0x04,0x24] # CHECK: lui $7, 1 # encoding: [0x01,0x00,0x07,0x3c] @@ -70,6 +72,7 @@ li $6,-2345 li $7,65538 li $8, ~7 + li $10, ~(0x101010) la $a0, 20 la $7,65538 Index: test/MC/Mips/mips64-expansions.s =================================================================== --- test/MC/Mips/mips64-expansions.s +++ test/MC/Mips/mips64-expansions.s @@ -76,35 +76,15 @@ # CHECK: addiu $12, $zero, -100 # encoding: [0x9c,0xff,0x0c,0x24] # CHECK: addiu $12, $zero, -1000 # encoding: [0x18,0xfc,0x0c,0x24] # CHECK: addiu $12, $zero, -10000 # encoding: [0xf0,0xd8,0x0c,0x24] -# CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] -# CHECK: ori $12, $12, 65535 # encoding: [0xff,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] -# CHECK: ori $12, $12, 65534 # encoding: [0xfe,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] +# CHECK: lui $12, 65534 # encoding: [0xfe,0xff,0x0c,0x3c] # CHECK: ori $12, $12, 31072 # encoding: [0x60,0x79,0x8c,0x35] -# CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] -# CHECK: ori $12, $12, 65535 # encoding: [0xff,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] -# CHECK: ori $12, $12, 65520 # encoding: [0xf0,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] +# CHECK: lui $12, 65520 # encoding: [0xf0,0xff,0x0c,0x3c] # CHECK: ori $12, $12, 48576 # encoding: [0xc0,0xbd,0x8c,0x35] -# CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] -# CHECK: ori $12, $12, 65535 # encoding: [0xff,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] -# CHECK: ori $12, $12, 65383 # encoding: [0x67,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] +# CHECK: lui $12, 65383 # encoding: [0x67,0xff,0x0c,0x3c] # CHECK: ori $12, $12, 27008 # encoding: [0x80,0x69,0x8c,0x35] -# CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] -# CHECK: ori $12, $12, 65535 # encoding: [0xff,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] -# CHECK: ori $12, $12, 64010 # encoding: [0x0a,0xfa,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] +# CHECK: lui $12, 64010 # encoding: [0x0a,0xfa,0x0c,0x3c] # CHECK: ori $12, $12, 7936 # encoding: [0x00,0x1f,0x8c,0x35] -# CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] -# CHECK: ori $12, $12, 65535 # encoding: [0xff,0xff,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] -# CHECK: ori $12, $12, 50277 # encoding: [0x65,0xc4,0x8c,0x35] -# CHECK: dsll $12, $12, 16 # encoding: [0x38,0x64,0x0c,0x00] +# CHECK: lui $12, 50277 # encoding: [0x65,0xc4,0x0c,0x3c] # CHECK: ori $12, $12, 13824 # encoding: [0x00,0x36,0x8c,0x35] # CHECK: lui $12, 65535 # encoding: [0xff,0xff,0x0c,0x3c] # CHECK: ori $12, $12, 65533 # encoding: [0xfd,0xff,0x8c,0x35] @@ -207,3 +187,13 @@ dli $t0, -100000000000000000 dli $t0, -1000000000000000000 dli $t0, -10000000000000000000 + + li $10, ~(0x101010) +# CHECK: lui $10, 65519 # encoding: [0xef,0xff,0x0a,0x3c] +# CHECK: ori $10, $10, 61423 # encoding: [0xef,0xef,0x4a,0x35] +# CHECK-NOT: dsll + + dli $10, ~(0x202020) +# CHECK: lui $10, 65503 # encoding: [0xdf,0xff,0x0a,0x3c] +# CHECK: ori $10, $10, 57311 # encoding: [0xdf,0xdf,0x4a,0x35] +# CHECK-NOT: dsll