Fix encoding of PC-relative LDRSHW with an immediate offset.
authorOwen Anderson <resistor@mac.com>
Mon, 12 Sep 2011 20:36:51 +0000 (20:36 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 12 Sep 2011 20:36:51 +0000 (20:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139537 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp
test/MC/ARM/basic-thumb2-instructions.s

index e65af677f80266020fd8c15ed38988b512966697..f0cb95f39b131a4ec26b69b4a676418573cca9a9 100644 (file)
@@ -713,17 +713,26 @@ getAddrModeImm12OpValue(const MCInst &MI, unsigned OpIdx,
     Imm12 = 0;
     isAdd = false ; // 'U' bit is set as part of the fixup.
 
-    assert(MO.isExpr() && "Unexpected machine operand type!");
-    const MCExpr *Expr = MO.getExpr();
+    if (MO.isExpr()) {
+      const MCExpr *Expr = MO.getExpr();
 
-    MCFixupKind Kind;
-    if (isThumb2())
-      Kind = MCFixupKind(ARM::fixup_t2_ldst_pcrel_12);
-    else
-      Kind = MCFixupKind(ARM::fixup_arm_ldst_pcrel_12);
-    Fixups.push_back(MCFixup::Create(0, Expr, Kind));
-
-    ++MCNumCPRelocations;
+      MCFixupKind Kind;
+      if (isThumb2())
+        Kind = MCFixupKind(ARM::fixup_t2_ldst_pcrel_12);
+      else
+        Kind = MCFixupKind(ARM::fixup_arm_ldst_pcrel_12);
+      Fixups.push_back(MCFixup::Create(0, Expr, Kind));
+
+      ++MCNumCPRelocations;
+    } else {
+      Reg = ARM::PC;
+      int32_t Offset = MO.getImm();
+      if (Offset < 0) {
+        Offset *= -1;
+        isAdd = false;
+      }
+      Imm12 = Offset;
+    }
   } else
     isAdd = EncodeAddrModeOpValues(MI, OpIdx, Reg, Imm12, Fixups);
 
index 8a4f6fc05cc439f66c2566703b81f4e0c3127c2d..d7df77735bcb671d9e8c66bf8f6aaadaa4081322 100644 (file)
@@ -850,10 +850,11 @@ _func:
 @ LDRSH(literal)
 @------------------------------------------------------------------------------
         ldrsh r5, _bar
+        ldrsh.w r4, #1435
 
 @ CHECK: ldrsh.w r5, _bar               @ encoding: [0xbf'A',0xf9'A',A,0x50'A']
 @ CHECK:      @   fixup A - offset: 0, value: _bar, kind: fixup_t2_ldst_pcrel_12
-
+@ CHECK: ldrsh.w r4, #1435               @ encoding: [0x3f,0xf9,0x9b,0x45]
 
 @------------------------------------------------------------------------------
 @ LDRSHT