From 17c0c4e7424187c50c3189566aa3432cee7cdc9a Mon Sep 17 00:00:00 2001 From: Volodymyr Turanskyy Date: Wed, 4 Jul 2018 16:11:15 +0000 Subject: [ARM] [Assembler] Support negative immediates: cover few missing cases Support for negative immediates was implemented in https://reviews.llvm.org/rL298380, however few instruction options were missing. This change adds negative immediates support and respective tests for the following: ADD ADDS ADDS.W AND.W ANDS BIC.W BICS BICS.W SUB SUBS SUBS.W Differential Revision: https://reviews.llvm.org/D48649 llvm-svn: 336286 --- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp') diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index df2e7ff709f..318bfe90d1d 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -1030,7 +1030,12 @@ public: if (!isImm()) return false; const MCConstantExpr *CE = dyn_cast(getImm()); if (!CE) return false; - int64_t Value = -CE->getValue(); + // isImm0_4095Neg is used with 32-bit immediates only. + // 32-bit immediates are zero extended to 64-bit when parsed, + // thus simple -CE->getValue() results in a big negative number, + // not a small positive number as intended + if ((CE->getValue() >> 32) > 0) return false; + uint32_t Value = -static_cast(CE->getValue()); return Value > 0 && Value < 4096; } @@ -2242,7 +2247,7 @@ public: // The operand is actually an imm0_4095, but we have its // negation in the assembly source, so twiddle it here. const MCConstantExpr *CE = dyn_cast(getImm()); - Inst.addOperand(MCOperand::createImm(-CE->getValue())); + Inst.addOperand(MCOperand::createImm(-(uint32_t)CE->getValue())); } void addUnsignedOffset_b8s2Operands(MCInst &Inst, unsigned N) const { -- cgit v1.2.3