[llvm] [ARM] Correctly handle .inst in IT and VPT blocks (PR #68902)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 12 08:29:32 PDT 2023


https://github.com/ostannard created https://github.com/llvm/llvm-project/pull/68902

Advance the IT and VPT block state when parsing the .inst directive, so that it is possible to use them to emit conditional instructions. If we don't do this, then a later instruction inside or just after the block will have a mis-matched condition, so be incorrectly reported as an error.

>From 171b4b74dc3a798e1f1fc0f1955a8f7ac77115c8 Mon Sep 17 00:00:00 2001
From: Oliver Stannard <oliver.stannard at arm.com>
Date: Thu, 12 Oct 2023 16:19:06 +0100
Subject: [PATCH] [ARM] Correctly handle .inst in IT and VPT blocks

Advance the IT and VPT block state when parsing the .inst directive, so
that it is possible to use them to emit conditional instructions. If we
don't do this, then a later instruction inside or just after the block
will have a mis-matched condition, so be incorrectly reported as an
error.
---
 .../lib/Target/ARM/AsmParser/ARMAsmParser.cpp |  2 ++
 llvm/test/MC/ARM/inst-directive-it-vpt.s      | 26 +++++++++++++++++++
 2 files changed, 28 insertions(+)
 create mode 100644 llvm/test/MC/ARM/inst-directive-it-vpt.s

diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
index 590887b765d7f56..373d5b59bca6640 100644
--- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
+++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
@@ -11981,6 +11981,8 @@ bool ARMAsmParser::parseDirectiveInst(SMLoc Loc, char Suffix) {
     }
 
     getTargetStreamer().emitInst(Value->getValue(), CurSuffix);
+    forwardITPosition();
+    forwardVPTPosition();
     return false;
   };
 
diff --git a/llvm/test/MC/ARM/inst-directive-it-vpt.s b/llvm/test/MC/ARM/inst-directive-it-vpt.s
new file mode 100644
index 000000000000000..8550d720ed42202
--- /dev/null
+++ b/llvm/test/MC/ARM/inst-directive-it-vpt.s
@@ -0,0 +1,26 @@
+// RUN: llvm-mc %s -triple armv8m.main -mattr=+mve -filetype asm -o - | FileCheck %s
+
+  .thumb
+
+// CHECK: it      eq
+// CHECK: .inst.n 0x3001
+// CHECK: add.w r0, r0, #1
+  it eq
+  .inst.n 0x3001 // addeq r0, #1
+  add r0, #1
+
+// CHECK: vpst
+// CHECK: .inst.w 0xef220844
+// CHECK: vadd.i32 q0, q1, q2
+  vpst
+  .inst.w 0xef220844 // vaddt.i32 q0, q1, q2
+  vadd.i32 q0, q1, q2
+
+// CHECK: ite eq
+// CHECK: .inst.n 0x3001
+// CHECK: addne r0, #1
+// CHECK: add.w r0, r0, #1
+  ite eq
+  .inst.n 0x3001 // addeq r0, #1
+  addne r0, #1
+  add r0, #1



More information about the llvm-commits mailing list