[PATCH] D153782: [ARM] allow long-call codegen for armv6-M eXecute Only (XO)

Ties Stuij via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 26 09:30:12 PDT 2023


stuij created this revision.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
stuij requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Recently eXecute Only (XO) codegen was also allowed for armv6-M. Previously this
was only implemented for ~armv7+, effectively if MOVW/MOVT is
available. Regarding long calls, we remove the check for MOVW/MOVT when
generating code for XO, which already was redundant as in the subtarget
initialization we already check if XO is valid for the target. And targets that
generate valid XO code should be able to handle the (wrapper globaladdress)
node.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153782

Files:
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/test/CodeGen/ARM/large-stack.ll
  llvm/test/CodeGen/Thumb/thumb-execute-only-long-calls.ll
  llvm/test/CodeGen/Thumb2/thumb2-execute-only-long-calls.ll


Index: llvm/test/CodeGen/Thumb2/thumb2-execute-only-long-calls.ll
===================================================================
--- llvm/test/CodeGen/Thumb2/thumb2-execute-only-long-calls.ll
+++ llvm/test/CodeGen/Thumb2/thumb2-execute-only-long-calls.ll
@@ -23,7 +23,7 @@
 ; RWPI:       movw    [[REG0:r[0-9]+]], :lower16:bar
 ; RWPI-NEXT:  movt    [[REG0]], :upper16:bar
 ; RWPI-NEXT:  blx     [[REG0]]
-; RWPI-NOT:   .LCPI0_0:
+; RWPI-NOT:   .LCPI1_0:
 entry:
   call void @bar()
   ret void
Index: llvm/test/CodeGen/Thumb/thumb-execute-only-long-calls.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/Thumb/thumb-execute-only-long-calls.ll
@@ -0,0 +1,34 @@
+; RUN: llc < %s -mtriple=thumbv6m-arm-none-eabi -relocation-model=static | FileCheck %s -check-prefixes=CHECK
+
+define void @fn() #0 {
+entry:
+; CHECK-LABEL: fn:
+; CHECK:       ldr [[REG:r[0-9]+]], .LCPI0_0
+; CHECK-NEXT:  blx [[REG]]
+; CHECK:       .LCPI0_0:
+; CHECK-NEXT:  .long   bar
+  call void @bar()
+  ret void
+}
+
+define void @execute_only_fn() #1 {
+; CHECK-LABEL: execute_only_fn:
+; CHECK:       movs    [[REG0:r[0-9]+]], :upper8_15:bar
+; CHECK-NEXT:  lsls    [[REG0]], r0, #8
+; CHECK-NEXT:  adds    [[REG0]], :upper0_7:bar
+; CHECK-NEXT:  lsls    [[REG0]], r0, #8
+; CHECK-NEXT:  adds    [[REG0]], :lower8_15:bar
+; CHECK-NEXT:  lsls    [[REG0]], r0, #8
+; CHECK-NEXT:  adds    [[REG0]], :lower0_7:bar
+; CHECK-NEXT:  blx     [[REG0]]
+; CHECK-NOT:   .LCPI1_0:
+
+entry:
+  call void @bar()
+  ret void
+}
+
+attributes #0 = { noinline optnone "target-features"="+thumb-mode,+long-calls" }
+attributes #1 = { noinline optnone "target-features"="+execute-only,+thumb-mode,+long-calls" }
+
+declare dso_local void @bar()
Index: llvm/test/CodeGen/ARM/large-stack.ll
===================================================================
--- llvm/test/CodeGen/ARM/large-stack.ll
+++ llvm/test/CodeGen/ARM/large-stack.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -mtriple=arm-eabi %s -o /dev/null
+; RUN: llc -mtriple=thumbv6m-eabi -mattr=+execute-only %s -o -
 
 define void @test1() {
     %tmp = alloca [ 64 x i32 ] , align 4
Index: llvm/lib/Target/ARM/ARMISelLowering.cpp
===================================================================
--- llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -2660,13 +2660,9 @@
     // those, the target's already in a register, so we don't need to do
     // anything extra.
     if (isa<GlobalAddressSDNode>(Callee)) {
-      // When generating execute-only code we use movw movt pair.
-      // Currently execute-only is only available for architectures that
-      // support movw movt, so we are safe to assume that.
       if (Subtarget->genExecuteOnly()) {
-        assert(Subtarget->useMovt() &&
-               "long-calls with execute-only requires movt and movw!");
-        ++NumMovwMovt;
+        if (Subtarget->useMovt())
+          ++NumMovwMovt;
         Callee = DAG.getNode(ARMISD::Wrapper, dl, PtrVt,
                              DAG.getTargetGlobalAddress(GVal, dl, PtrVt));
       } else {
@@ -2685,13 +2681,9 @@
     } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) {
       const char *Sym = S->getSymbol();
 
-      // When generating execute-only code we use movw movt pair.
-      // Currently execute-only is only available for architectures that
-      // support movw movt, so we are safe to assume that.
       if (Subtarget->genExecuteOnly()) {
-        assert(Subtarget->useMovt() &&
-               "long-calls with execute-only requires movt and movw!");
-        ++NumMovwMovt;
+        if (Subtarget->useMovt())
+          ++NumMovwMovt;
         Callee = DAG.getNode(ARMISD::Wrapper, dl, PtrVt,
                              DAG.getTargetGlobalAddress(GVal, dl, PtrVt));
       } else {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153782.534604.patch
Type: text/x-patch
Size: 3853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230626/063ae164/attachment.bin>


More information about the llvm-commits mailing list