[llvm] r278789 - Correct the upper bound for a CBZ/CBNZ branch target.

Prakhar Bahuguna via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 16 03:41:56 PDT 2016


Author: prakhar
Date: Tue Aug 16 05:41:56 2016
New Revision: 278789

URL: http://llvm.org/viewvc/llvm-project?rev=278789&view=rev
Log:
Correct the upper bound for a CBZ/CBNZ branch target.

Summary:
Fix for the upper bound check that was causing a build failure.

Reviewers: olista01, rengolin, t.p.northover

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D23501

Modified:
    llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
    llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s

Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp?rev=278789&r1=278788&r2=278789&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp Tue Aug 16 05:41:56 2016
@@ -578,8 +578,10 @@ unsigned ARMAsmBackend::adjustFixupValue
     // Offset by 4, and don't encode the low two bits.
     return ((Value - 4) >> 2) & 0xff;
   case ARM::fixup_arm_thumb_cb: {
-    // CB instructions can only branch to offsets in [0, 126] in multiples of 2
-    if (Ctx && ((int64_t)Value < 0 || Value > 0x3e || Value & 1)) {
+    // CB instructions can only branch to offsets in [4, 126] in multiples of 2
+    // so ensure that the raw value LSB is zero and it lies in [2, 130].
+    // An offset of 2 will be relaxed to a NOP.
+    if (Ctx && ((int64_t)Value < 2 || Value > 0x82 || Value & 1)) {
       Ctx->reportError(Fixup.getLoc(), "out of range pc-relative fixup value");
       return 0;
     }

Modified: llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s?rev=278789&r1=278788&r2=278789&view=diff
==============================================================================
--- llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s (original)
+++ llvm/trunk/test/MC/ARM/thumb-cb-negative-offsets.s Tue Aug 16 05:41:56 2016
@@ -16,4 +16,16 @@ label0:
 
   .space 1000
 label1:
-  .word 4
+  nop
+
+@ CHECK: out of range pc-relative fixup value
+  cbz r0, label2
+  .space 130
+label2:
+  nop
+
+@ CHECK-NOT: label3
+  cbnz r0, label3
+  .space 128
+label3:
+  nop




More information about the llvm-commits mailing list