[llvm] r335593 - ARM: diagnose unpredictable IT instructions

Tim Northover via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 26 04:38:41 PDT 2018


Author: tnorthover
Date: Tue Jun 26 04:38:41 2018
New Revision: 335593

URL: http://llvm.org/viewvc/llvm-project?rev=335593&view=rev
Log:
ARM: diagnose unpredictable IT instructions

IT instructions are allowed to have the 'AL' predicate, but it must never
result in an 'NV' predicated instruction. Essentially this means that all
branches must be 't' rather than 'e' if the predicate is 'AL'.

This patch adds a diagnostic for this during assembly (error because parsing
hits an assertion if allowed to continue) and an annotation during disassembly.

Added:
    llvm/trunk/test/MC/ARM/it-nv.s
    llvm/trunk/test/tools/llvm-objdump/it-nv.txt
Modified:
    llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
    llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp

Modified: llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp?rev=335593&r1=335592&r2=335593&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmParser/ARMAsmParser.cpp Tue Jun 26 04:38:41 2018
@@ -6348,6 +6348,21 @@ bool ARMAsmParser::validateInstruction(M
 
   const unsigned Opcode = Inst.getOpcode();
   switch (Opcode) {
+  case ARM::t2IT: {
+    // Encoding is unpredictable if it ever results in a notional 'NV'
+    // predicate. Since we don't parse 'NV' directly this means an 'AL'
+    // predicate with an "else" mask bit.
+    unsigned Cond = Inst.getOperand(0).getImm();
+    unsigned Mask = Inst.getOperand(1).getImm();
+
+    // Mask hasn't been modified to the IT instruction encoding yet so
+    // conditions only allowing a 't' are a block of 1s starting at bit 3
+    // followed by all 0s. Easiest way is to just list the 4 possibilities.
+    if (Cond == ARMCC::AL && Mask != 8 && Mask != 12 && Mask != 14 &&
+        Mask != 15)
+      return Error(Loc, "unpredictable IT predicate sequence");
+    break;
+  }
   case ARM::LDRD:
   case ARM::LDRD_PRE:
   case ARM::LDRD_POST: {

Modified: llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp?rev=335593&r1=335592&r2=335593&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp (original)
+++ llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp Tue Jun 26 04:38:41 2018
@@ -729,10 +729,13 @@ DecodeStatus ThumbDisassembler::getInstr
     // code and mask operands so that we can apply them correctly
     // to the subsequent instructions.
     if (MI.getOpcode() == ARM::t2IT) {
-
       unsigned Firstcond = MI.getOperand(0).getImm();
       unsigned Mask = MI.getOperand(1).getImm();
       ITBlock.setITState(Firstcond, Mask);
+
+      // An IT instruction that would give a 'NV' predicate is unpredictable.
+      if (Firstcond == ARMCC::AL && !isPowerOf2_32(Mask))
+        CS << "unpredictable IT predicate sequence";
     }
 
     return Result;

Added: llvm/trunk/test/MC/ARM/it-nv.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/it-nv.s?rev=335593&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/it-nv.s (added)
+++ llvm/trunk/test/MC/ARM/it-nv.s Tue Jun 26 04:38:41 2018
@@ -0,0 +1,47 @@
+@ RUN: not llvm-mc -triple thumbv7m-apple-macho %s 2> %t.errs
+@ RUN: FileCheck %s < %t.errs --check-prefix=CHECK-ERRS
+
+@ CHECK-ERRS: error: unpredictable IT predicate sequence
+@ CHECK-ERRS:     ite al
+@ CHECK-ERRS: error: unpredictable IT predicate sequence
+@ CHECK-ERRS:     itee al
+@ CHECK-ERRS: error: unpredictable IT predicate sequence
+@ CHECK-ERRS:     itet al
+@ CHECK-ERRS: error: unpredictable IT predicate sequence
+@ CHECK-ERRS:     itte al
+@ CHECK-ERRS: error: unpredictable IT predicate sequence
+@ CHECK-ERRS:     ittte al
+    ite al
+    itee al
+    itet al
+    itte al
+    ittte al
+
+@ CHECK-ERRS-NOT: error
+    it al
+    nop
+
+    itt al
+    nop
+    nop
+
+    ittt al
+    nop
+    nop
+    nop
+
+    itttt al
+    nop
+    nop
+    nop
+    nop
+
+    ite eq
+    nopeq
+    nopne
+
+    iteet hi
+    nophi
+    nopls
+    nopls
+    nophi

Added: llvm/trunk/test/tools/llvm-objdump/it-nv.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/it-nv.txt?rev=335593&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/it-nv.txt (added)
+++ llvm/trunk/test/tools/llvm-objdump/it-nv.txt Tue Jun 26 04:38:41 2018
@@ -0,0 +1,10 @@
+# RUN: llvm-objdump -macho -d %p/Inputs/it-nv.o | FileCheck %s
+
+# CHECK: ite	al @ unpredictable IT predicate sequence
+# CHECK: itet	al @ unpredictable IT predicate sequence
+# CHECK: itte	al @ unpredictable IT predicate sequence
+# CHECK: ite	eq{{$}}
+# CHECK: it	al{{$}}
+# CHECK: itt	al{{$}}
+# CHECK: ittt	al{{$}}
+# CHECK: itttt	al{{$}}




More information about the llvm-commits mailing list