ARM assembler should prefer non-aliases encoding of cmp.
authorJim Grosbach <grosbach@apple.com>
Fri, 30 Mar 2012 19:59:02 +0000 (19:59 +0000)
committerJim Grosbach <grosbach@apple.com>
Fri, 30 Mar 2012 19:59:02 +0000 (19:59 +0000)
When an immediate is both a value [t2_]so_imm and a [t2_]so_imm_neg,
we want to use the non-negated form to make sure we prefer the normal
encoding, not the aliased encoding via the negation of, e.g., 'cmp.w'.

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

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

index f8edced2085771f943192d6bc5e0f5047aefa567..0729da1a8ea20c27768225ac4f035d740aedc3c8 100644 (file)
@@ -782,8 +782,9 @@ public:
     const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
     if (!CE) return false;
     int64_t Value = CE->getValue();
-    // Negation must be representable as an so_imm and be non-zero.
-    return Value && ARM_AM::getSOImmVal(-Value) != -1;
+    // Only use this when not representable as a plain so_imm.
+    return ARM_AM::getSOImmVal(Value) == -1 &&
+      ARM_AM::getSOImmVal(-Value) != -1;
   }
   bool isT2SOImm() const {
     if (!isImm()) return false;
@@ -804,8 +805,9 @@ public:
     const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm());
     if (!CE) return false;
     int64_t Value = CE->getValue();
-    // Negation must be representable as a t2_so_imm and be non-zero.
-    return Value && ARM_AM::getT2SOImmVal(-Value) != -1;
+    // Only use this when not representable as a plain so_imm.
+    return ARM_AM::getT2SOImmVal(Value) == -1 &&
+      ARM_AM::getT2SOImmVal(-Value) != -1;
   }
   bool isSetEndImm() const {
     if (!isImm()) return false;
index 0091a9fed2bac9ddaaaacac5b4f31b666173eb8c..0b8257fdb95a5eaf312542d23c4b12dddbefbb7b 100644 (file)
@@ -372,7 +372,8 @@ _func:
         cmp sp, r6, lsr #1
         cmp r2, r5, asr #24
         cmp r1, r4, ror #15
-        cmp r0, #-2
+        cmp r2, #-2
+        cmp r9, #1
 
 @ CHECK: cmp.w r5, #65280              @ encoding: [0xb5,0xf5,0x7f,0x4f]
 @ CHECK: cmp.w r4, r12                 @ encoding: [0xb4,0xeb,0x0c,0x0f]
@@ -381,7 +382,9 @@ _func:
 @ CHECK: cmp.w sp, r6, lsr #1          @ encoding: [0xbd,0xeb,0x56,0x0f]
 @ CHECK: cmp.w r2, r5, asr #24         @ encoding: [0xb2,0xeb,0x25,0x6f]
 @ CHECK: cmp.w r1, r4, ror #15         @ encoding: [0xb1,0xeb,0xf4,0x3f]
-@ CHECK: cmn.w r0, #2                  @ encoding: [0x10,0xf1,0x02,0x0f]
+@ CHECK: cmn.w r2, #2                  @ encoding: [0x12,0xf1,0x02,0x0f]
+@ CHECK: cmp.w r9, #1                  @ encoding: [0xb9,0xf1,0x01,0x0f]
+
 
 @------------------------------------------------------------------------------
 @ DBG