From a59d48916273780a524af95d89a217193bd406c2 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 30 Aug 2011 22:15:17 +0000 Subject: [PATCH] Fix encoding of CBZ/CBNZ Thumb2 instructions with immediate offsets rather than labels. llvm-svn: 138837 --- lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp | 5 ++++- test/MC/ARM/basic-thumb2-instructions.s | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp b/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp index ab2162cbebb..7cac54c610b 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMMCCodeEmitter.cpp @@ -501,7 +501,10 @@ getThumbBCCTargetOpValue(const MCInst &MI, unsigned OpIdx, uint32_t ARMMCCodeEmitter:: getThumbCBTargetOpValue(const MCInst &MI, unsigned OpIdx, SmallVectorImpl &Fixups) const { - return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_cb, Fixups); + const MCOperand MO = MI.getOperand(OpIdx); + if (MO.isExpr()) + return ::getBranchTargetOpValue(MI, OpIdx, ARM::fixup_arm_thumb_cb, Fixups); + return (MO.getImm() >> 1); } /// Return true if this branch has a non-always predication diff --git a/test/MC/ARM/basic-thumb2-instructions.s b/test/MC/ARM/basic-thumb2-instructions.s index 423e5bc3166..61d651472ee 100644 --- a/test/MC/ARM/basic-thumb2-instructions.s +++ b/test/MC/ARM/basic-thumb2-instructions.s @@ -37,6 +37,15 @@ _func: @ CHECK: adc r4, r2, #2139095040 @ encoding: [0x42,0xf1,0xff,0x44] @ CHECK: adc r4, r2, #1664 @ encoding: [0x42,0xf5,0xd0,0x64] +@------------------------------------------------------------------------------ +@ CBZ/CBNZ +@------------------------------------------------------------------------------ + cbnz r7, #6 + cbnz r7, #12 + +@ CHECK: cbnz r7, #6 @ encoding: [0x1f,0xb9] +@ CHECK: cbnz r7, #12 @ encoding: [0x37,0xb9] + @------------------------------------------------------------------------------ @ IT @------------------------------------------------------------------------------