Index: lib/Target/Mips/AsmParser/MipsAsmParser.cpp =================================================================== --- lib/Target/Mips/AsmParser/MipsAsmParser.cpp +++ lib/Target/Mips/AsmParser/MipsAsmParser.cpp @@ -3552,11 +3552,18 @@ (DstRegClassID == Mips::GPR64RegClassID); if (IsImmOpnd) { + // Now `emitLoadWithImmOffset` knows + // how to transform 32-bit offsets only. + int64_t Imm = Inst.getOperand(2).getImm(); + if (!isIntN(32, Imm)) { + Error(IDLoc, "expected memory with 32-bit signed offset"); + return; + } + // Try to use DstReg as the temporary. if (IsGPR && (BaseReg != DstReg)) { - TOut.emitLoadWithImmOffset(Inst.getOpcode(), DstReg, BaseReg, - Inst.getOperand(2).getImm(), DstReg, IDLoc, - STI); + TOut.emitLoadWithImmOffset(Inst.getOpcode(), DstReg, BaseReg, Imm, DstReg, + IDLoc, STI); return; } @@ -3566,8 +3573,8 @@ if (!ATReg) return; - TOut.emitLoadWithImmOffset(Inst.getOpcode(), DstReg, BaseReg, - Inst.getOperand(2).getImm(), ATReg, IDLoc, STI); + TOut.emitLoadWithImmOffset(Inst.getOpcode(), DstReg, BaseReg, Imm, ATReg, + IDLoc, STI); return; } Index: lib/Target/Mips/MipsInstrInfo.td =================================================================== --- lib/Target/Mips/MipsInstrInfo.td +++ lib/Target/Mips/MipsInstrInfo.td @@ -1997,9 +1997,9 @@ /// Load and Store Instructions /// aligned -def LB : LoadMemory<"lb", GPR32Opnd, mem_simm16, sextloadi8, II_LB>, MMRel, +def LB : LoadMemory<"lb", GPR32Opnd, mem, sextloadi8, II_LB>, MMRel, LW_FM<0x20>; -def LBu : LoadMemory<"lbu", GPR32Opnd, mem_simm16, zextloadi8, II_LBU, +def LBu : LoadMemory<"lbu", GPR32Opnd, mem, zextloadi8, II_LBU, addrDefault>, MMRel, LW_FM<0x24>; let AdditionalPredicates = [NotInMicroMips] in { def LH : LoadMemory<"lh", GPR32Opnd, mem_simm16, sextloadi16, II_LH, Index: test/MC/Mips/micromips/invalid.s =================================================================== --- test/MC/Mips/micromips/invalid.s +++ test/MC/Mips/micromips/invalid.s @@ -121,10 +121,10 @@ xori $3, 65536 # CHECK: :[[@LINE]]:12: error: expected 16-bit unsigned immediate not $3, 4 # CHECK: :[[@LINE]]:11: error: invalid operand for instruction lb $32, 8($5) # CHECK: :[[@LINE]]:6: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:10: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:10: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:12: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:7: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:11: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:11: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:13: error: invalid register number Index: test/MC/Mips/micromips32r6/invalid.s =================================================================== --- test/MC/Mips/micromips32r6/invalid.s +++ test/MC/Mips/micromips32r6/invalid.s @@ -253,12 +253,12 @@ xori $3, 65536 # CHECK: :[[@LINE]]:12: error: expected 16-bit unsigned immediate not $3, 4 # CHECK: :[[@LINE]]:11: error: invalid operand for instruction lb $32, 8($5) # CHECK: :[[@LINE]]:6: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:10: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:10: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:12: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:7: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:11: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:11: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:3: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:13: error: invalid register number ldc1 $f32, 300($10) # CHECK: :[[@LINE]]:8: error: invalid operand for instruction ldc1 $f7, -32769($10) # CHECK: :[[@LINE]]:13: error: expected memory with 16-bit signed offset Index: test/MC/Mips/mips-expansions.s =================================================================== --- test/MC/Mips/mips-expansions.s +++ test/MC/Mips/mips-expansions.s @@ -13,6 +13,24 @@ # CHECK-LE: addiu $8, $8, %lo($tmp0) # encoding: [A,A,0x08,0x25] # CHECK-LE: # fixup A - offset: 0, value: %lo($tmp0), kind: fixup_Mips_LO16 + lb $4, 0x8000 +# CHECK-LE: lui $4, 1 # encoding: [0x01,0x00,0x04,0x3c] +# CHECK-LE: lb $4, -32768($4) # encoding: [0x00,0x80,0x84,0x80] + + lb $4, 0x20004($3) +# CHECK-LE: lui $4, 2 # encoding: [0x02,0x00,0x04,0x3c] +# CHECK-LE: addu $4, $4, $3 # encoding: [0x21,0x20,0x83,0x00] +# CHECK-LE: lb $4, 4($4) # encoding: [0x04,0x00,0x84,0x80] + + lbu $4, 0x8000 +# CHECK-LE: lui $4, 1 # encoding: [0x01,0x00,0x04,0x3c] +# CHECK-LE: lbu $4, -32768($4) # encoding: [0x00,0x80,0x84,0x90] + + lbu $4, 0x20004($3) +# CHECK-LE: lui $4, 2 # encoding: [0x02,0x00,0x04,0x3c] +# CHECK-LE: addu $4, $4, $3 # encoding: [0x21,0x20,0x83,0x00] +# CHECK-LE: lbu $4, 4($4) # encoding: [0x04,0x00,0x84,0x90] + # LW/SW and LDC1/SDC1 of symbol address, done by MipsAsmParser::expandMemInst(): .set noat lw $10, symbol($4) Index: test/MC/Mips/mips32r5/invalid.s =================================================================== --- test/MC/Mips/mips32r5/invalid.s +++ test/MC/Mips/mips32r5/invalid.s @@ -21,12 +21,12 @@ mfc2 $4, $3, -1 # CHECK: :[[@LINE]]:23: error: expected 3-bit unsigned immediate mfc2 $4, $3, 8 # CHECK: :[[@LINE]]:23: error: expected 3-bit unsigned immediate lb $32, 8($5) # CHECK: :[[@LINE]]:12: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:18: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:13: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:19: error: invalid register number ldc1 $f32, 300($10) # CHECK: :[[@LINE]]:14: error: invalid operand for instruction ldc1 $f7, -32769($10) # CHECK: :[[@LINE]]:19: error: expected memory with 16-bit signed offset Index: test/MC/Mips/mips32r6/invalid.s =================================================================== --- test/MC/Mips/mips32r6/invalid.s +++ test/MC/Mips/mips32r6/invalid.s @@ -146,12 +146,12 @@ sync -1 # CHECK: :[[@LINE]]:14: error: expected 5-bit unsigned immediate sync 32 # CHECK: :[[@LINE]]:14: error: expected 5-bit unsigned immediate lb $32, 8($5) # CHECK: :[[@LINE]]:12: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:18: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:13: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:19: error: invalid register number ldc1 $f32, 300($10) # CHECK: :[[@LINE]]:14: error: invalid operand for instruction ldc1 $f7, -32769($10) # CHECK: :[[@LINE]]:19: error: expected memory with 16-bit signed offset Index: test/MC/Mips/mips64r5/invalid.s =================================================================== --- test/MC/Mips/mips64r5/invalid.s +++ test/MC/Mips/mips64r5/invalid.s @@ -20,12 +20,12 @@ dmfc0 $4, $3, 8 # CHECK: :[[@LINE]]:24: error: expected 3-bit unsigned immediate sd $32, 65536($32) # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid register number lb $32, 8($5) # CHECK: :[[@LINE]]:12: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:18: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:13: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:19: error: invalid register number ldc1 $f32, 300($10) # CHECK: :[[@LINE]]:14: error: invalid operand for instruction ldc1 $f7, -32769($10) # CHECK: :[[@LINE]]:19: error: expected memory with 16-bit signed offset Index: test/MC/Mips/mips64r6/invalid.s =================================================================== --- test/MC/Mips/mips64r6/invalid.s +++ test/MC/Mips/mips64r6/invalid.s @@ -195,12 +195,12 @@ dsrlv $2, $4, 2 # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid operand for instruction dsrlv $32, $32, $32 # CHECK: :[[@LINE]]:{{[0-9]+}}: error: invalid register number lb $32, 8($5) # CHECK: :[[@LINE]]:12: error: invalid register number - lb $4, -32769($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset - lb $4, 32768($5) # CHECK: :[[@LINE]]:16: error: expected memory with 16-bit signed offset + lb $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lb $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lb $4, 8($32) # CHECK: :[[@LINE]]:18: error: invalid register number lbu $32, 8($5) # CHECK: :[[@LINE]]:13: error: invalid register number - lbu $4, -32769($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset - lbu $4, 32768($5) # CHECK: :[[@LINE]]:17: error: expected memory with 16-bit signed offset + lbu $4, -2147483649($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset + lbu $4, 2147483648($5) # CHECK: :[[@LINE]]:9: error: expected memory with 32-bit signed offset lbu $4, 8($32) # CHECK: :[[@LINE]]:19: error: invalid register number ldc1 $f32, 300($10) # CHECK: :[[@LINE]]:14: error: invalid operand for instruction ldc1 $f7, -32769($10) # CHECK: :[[@LINE]]:19: error: expected memory with 16-bit signed offset