[llvm] r375043 - [AArch64] Fix offset calculation
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 16 14:41:05 PDT 2019
Author: smeenai
Date: Wed Oct 16 14:41:05 2019
New Revision: 375043
URL: http://llvm.org/viewvc/llvm-project?rev=375043&view=rev
Log:
[AArch64] Fix offset calculation
r374772 changed Offset to be an int64_t but left NewOffset as an int.
Scale is unsigned, so in the calculation `Offset - NewOffset * Scale`,
`NewOffset * Scale` was promoted to unsigned and was then zero-extended
to 64 bits, leading to an incorrect computation which manifested as an
out-of-memory when building the Swift standard library for Android
aarch64. Promote NewOffset to int64_t to fix this, and promote
EmittableOffset as well, since its one user passes it to a function
which takes an int64_t anyway.
Test case based on a suggestion by Sander de Smalen!
Differential Revision: https://reviews.llvm.org/D69018
Added:
llvm/trunk/test/CodeGen/AArch64/framelayout-offset-immediate-change.mir
Modified:
llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.h
Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp?rev=375043&r1=375042&r2=375043&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.cpp Wed Oct 16 14:41:05 2019
@@ -3368,7 +3368,7 @@ int llvm::isAArch64FrameOffsetLegal(cons
StackOffset &SOffset,
bool *OutUseUnscaledOp,
unsigned *OutUnscaledOp,
- int *EmittableOffset) {
+ int64_t *EmittableOffset) {
// Set output values in case of early exit.
if (EmittableOffset)
*EmittableOffset = 0;
@@ -3430,7 +3430,7 @@ int llvm::isAArch64FrameOffsetLegal(cons
"Cannot have remainder when using unscaled op");
assert(MinOff < MaxOff && "Unexpected Min/Max offsets");
- int NewOffset = Offset / Scale;
+ int64_t NewOffset = Offset / Scale;
if (MinOff <= NewOffset && NewOffset <= MaxOff)
Offset = Remainder;
else {
@@ -3471,7 +3471,7 @@ bool llvm::rewriteAArch64FrameIndex(Mach
return true;
}
- int NewOffset;
+ int64_t NewOffset;
unsigned UnscaledOp;
bool UseUnscaledOp;
int Status = isAArch64FrameOffsetLegal(MI, Offset, &UseUnscaledOp,
Modified: llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.h?rev=375043&r1=375042&r2=375043&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.h (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64InstrInfo.h Wed Oct 16 14:41:05 2019
@@ -335,7 +335,7 @@ enum AArch64FrameOffsetStatus {
int isAArch64FrameOffsetLegal(const MachineInstr &MI, StackOffset &Offset,
bool *OutUseUnscaledOp = nullptr,
unsigned *OutUnscaledOp = nullptr,
- int *EmittableOffset = nullptr);
+ int64_t *EmittableOffset = nullptr);
static inline bool isUncondBranchOpcode(int Opc) { return Opc == AArch64::B; }
Added: llvm/trunk/test/CodeGen/AArch64/framelayout-offset-immediate-change.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/framelayout-offset-immediate-change.mir?rev=375043&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/framelayout-offset-immediate-change.mir (added)
+++ llvm/trunk/test/CodeGen/AArch64/framelayout-offset-immediate-change.mir Wed Oct 16 14:41:05 2019
@@ -0,0 +1,17 @@
+# RUN: llc -mtriple=aarch64-none-linux-gnu -run-pass=prologepilog %s -o - | FileCheck %s
+---
+name: framelayout_offset_immediate_change
+tracksRegLiveness: true
+fixedStack:
+ - { id: 0, offset: 0, size: 1}
+body: |
+ bb.0:
+ $x0 = LDURXi %fixed-stack.0, -264
+ RET_ReallyLR
+...
+# CHECK: name: framelayout_offset_immediate_change
+# CHECK: body: |
+# CHECK-NEXT: bb.0:
+# CHECK-NEXT: $x8 = SUBXri $sp, 8, 0
+# CHECK-NEXT: $x0 = LDURXi killed $x8, -256
+# CHECK-NEXT: RET_ReallyLR
More information about the llvm-commits
mailing list