[PATCH] D72123: Lower TAGPstack with negative offset to SUBG.
Evgenii Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 2 18:16:09 PST 2020
eugenis created this revision.
eugenis added reviewers: ostannard, pcc.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
This never really occurs in the current codegen, so only a MIR test is
possible.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72123
Files:
llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/test/CodeGen/AArch64/addg_subg.mir
Index: llvm/test/CodeGen/AArch64/addg_subg.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/addg_subg.mir
@@ -0,0 +1,37 @@
+# RUN: llc -mtriple=aarch64 -run-pass=prologepilog,aarch64-expand-pseudo %s -o - | FileCheck %s
+
+# CHECK: renamable $x8 = IRG $sp, $xzr
+
+# CHECK: renamable $x0 = ADDG $x8, 0, 0
+# CHECK: renamable $x0 = ADDG $x8, 5, 0
+# CHECK: renamable $x0 = ADDG $x8, 63, 0
+# CHECK: $[[R:x[0-9]+]] = ADDXri $x8, 16, 0
+# CHECK: renamable $x0 = ADDG killed $[[R]], 63, 0
+
+# CHECK: renamable $x0 = SUBG $x8, 5, 0
+# CHECK: renamable $x0 = SUBG $x8, 63, 0
+# CHECK: $[[R:x[0-9]+]] = SUBXri $x8, 16, 0
+# CHECK: renamable $x0 = SUBG killed $[[R]], 63, 0
+
+---
+name: subg
+stack:
+ - { id: 0, type: default, offset: 0, size: 16, alignment: 16,
+ stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+ local-offset: -16, debug-info-variable: '', debug-info-expression: '',
+ debug-info-location: '' }
+body: |
+ bb.0.entry:
+ renamable $x8 = IRGstack $sp, $xzr
+
+ renamable $x0 = TAGPstack %stack.0, 0, killed renamable $x8, 0
+ renamable $x0 = TAGPstack %stack.0, 5, killed renamable $x8, 0
+ renamable $x0 = TAGPstack %stack.0, 63, killed renamable $x8, 0
+ renamable $x0 = TAGPstack %stack.0, 64, killed renamable $x8, 0
+
+ renamable $x0 = TAGPstack %stack.0, -5, killed renamable $x8, 0
+ renamable $x0 = TAGPstack %stack.0, -63, killed renamable $x8, 0
+ renamable $x0 = TAGPstack %stack.0, -64, killed renamable $x8, 0
+ RET_ReallyLR
+
+...
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -2188,12 +2188,19 @@
MaxOffset = 4095;
break;
case AArch64::ADDG:
- case AArch64::TAGPstack:
Scale = 16;
Width = 0;
MinOffset = 0;
MaxOffset = 63;
break;
+ case AArch64::TAGPstack:
+ Scale = 16;
+ Width = 0;
+ // TAGP with a negative offset turns into SUBP, which has a maximum offset
+ // of 63 (not 64!).
+ MinOffset = -63;
+ MaxOffset = 63;
+ break;
case AArch64::LDG:
case AArch64::STGOffset:
case AArch64::STZGOffset:
Index: llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
+++ llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
@@ -696,10 +696,12 @@
return true;
}
case AArch64::TAGPstack: {
- BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::ADDG))
+ int64_t Offset = MI.getOperand(2).getImm();
+ BuildMI(MBB, MBBI, MI.getDebugLoc(),
+ TII->get(Offset >= 0 ? AArch64::ADDG : AArch64::SUBG))
.add(MI.getOperand(0))
.add(MI.getOperand(1))
- .add(MI.getOperand(2))
+ .addImm(std::abs(Offset))
.add(MI.getOperand(4));
MI.eraseFromParent();
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72123.235983.patch
Type: text/x-patch
Size: 3087 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200103/1d8a3a7a/attachment.bin>
More information about the llvm-commits
mailing list