Make sure the alternate PC+imm syntax of LDR instruction with a small
authorKevin Enderby <enderby@apple.com>
Fri, 14 Dec 2012 23:04:25 +0000 (23:04 +0000)
committerKevin Enderby <enderby@apple.com>
Fri, 14 Dec 2012 23:04:25 +0000 (23:04 +0000)
immediate generates the narrow version.  Needed when doing round-trip
assemble/disassemble testing using the alternate syntax that specifies
'pc' directly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170255 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/ARM/AsmParser/ARMAsmParser.cpp
test/MC/ARM/basic-thumb2-instructions.s

index 4685b1d193c28abedc3bb04762e0b62011f987be..6b42239747e543602fb60945c6bdfb4ce89d9278 100644 (file)
@@ -5723,7 +5723,12 @@ processInstruction(MCInst &Inst,
   }
   // Aliases for alternate PC+imm syntax of LDR instructions.
   case ARM::t2LDRpcrel:
-    Inst.setOpcode(ARM::t2LDRpci);
+    // Select the narrow version if the immediate will fit.
+    if (Inst.getOperand(1).getImm() > 0 &&
+        Inst.getOperand(1).getImm() <= 0xff)
+      Inst.setOpcode(ARM::tLDRpci);
+    else
+      Inst.setOpcode(ARM::t2LDRpci);
     return true;
   case ARM::t2LDRBpcrel:
     Inst.setOpcode(ARM::t2LDRBpci);
index 23d9f5977a296766dd48afe970ad63ea14d162af..d495c91c0e7ce9959973d6828ebdaf2d7a19b223 100644 (file)
@@ -3509,3 +3509,7 @@ _func:
 @ CHECK: ldrh.w        r11, [pc, #-22]         @ encoding: [0x3f,0xf8,0x16,0xb0]
 @ CHECK: ldrsb.w r11, [pc, #-22]        @ encoding: [0x1f,0xf9,0x16,0xb0]
 @ CHECK: ldrsh.w r11, [pc, #-22]        @ encoding: [0x3f,0xf9,0x16,0xb0]
+
+@ rdar://12596361
+        ldr r1, [pc, #12]
+@ CHECK: ldr.n r1, [pc, #12]        @ encoding: [0x03,0x49]