Skip to content

Commit

Permalink
[mips] Make symbols an acceptable branch target when expanding compar…
Browse files Browse the repository at this point in the history
…e-to-immediate-and-branch macros.

Reviewers: vkalintiris

Subscribers: llvm-commits, vkalintiris, dim, seanbruno, dsanders

Differential Revision: http://reviews.llvm.org/D15369

llvm-svn: 262213
  • Loading branch information
dsandersllvm committed Feb 29, 2016
1 parent f5b2a47 commit 90f0d0b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llvm/lib/Target/Mips/AsmParser/MipsAsmParser.cpp
Expand Up @@ -2559,7 +2559,8 @@ bool MipsAsmParser::expandBranchImm(MCInst &Inst, SMLoc IDLoc,
assert(ImmOp.isImm() && "expected immediate operand kind");

const MCOperand &MemOffsetOp = Inst.getOperand(2);
assert(MemOffsetOp.isImm() && "expected immediate operand kind");
assert((MemOffsetOp.isImm() || MemOffsetOp.isExpr()) &&
"expected immediate or expression operand");

unsigned OpCode = 0;
switch(Inst.getOpcode()) {
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/MC/Mips/mips-expansions.s
Expand Up @@ -129,6 +129,12 @@
beq $2, 0x10000, 1332
# CHECK-LE: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c]
# CHECK-LE: beq $2, $1, 1332 # encoding: [0x4d,0x01,0x41,0x10]
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]

beq $2, 65538, foo
# CHECK-LE: lui $1, 1 # encoding: [0x01,0x00,0x01,0x3c]
# CHECK-LE: ori $1, $1, 2 # encoding: [0x02,0x00,0x21,0x34]
# CHECK-LE: beq $2, $1, foo # encoding: [A,A,0x41,0x10]
# CHECK-LE: nop # encoding: [0x00,0x00,0x00,0x00]

# Test ULH with immediate operand.
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/MC/Mips/mips64-expansions.s
Expand Up @@ -84,6 +84,17 @@
# CHECK: beq $2, $1, 1332 # encoding: [0x4d,0x01,0x41,0x10]
# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]

# Test one with a symbol in the third operand.
sym:
bne $2, 0x100010001, sym
# CHECK: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24]
# CHECK: dsll $1, $1, 16 # encoding: [0x38,0x0c,0x01,0x00]
# CHECK: ori $1, $1, 1 # encoding: [0x01,0x00,0x21,0x34]
# CHECK: dsll $1, $1, 16 # encoding: [0x38,0x0c,0x01,0x00]
# CHECK: ori $1, $1, 1 # encoding: [0x01,0x00,0x21,0x34]
# CHECK: bne $2, $1, sym # encoding: [A,A,0x41,0x14]
# CHECK: nop # encoding: [0x00,0x00,0x00,0x00]

# Test ulhu with 64-bit immediate addresses.
ulhu $8, 0x100010001
# CHECK: addiu $1, $zero, 1 # encoding: [0x01,0x00,0x01,0x24]
Expand Down

0 comments on commit 90f0d0b

Please sign in to comment.