Skip to content

Commit 9bc5c88

Browse files
committed
Merging r316035:
------------------------------------------------------------------------ r316035 | tnorthover | 2017-10-17 14:43:52 -0700 (Tue, 17 Oct 2017) | 6 lines AArch64: account for possible frame index operand in compares. If the address of a local is used in a comparison, AArch64 can fold the address-calculation into the comparison via "adds". Unfortunately, a couple of places (both hit in this one test) are not ready to deal with that yet and just assume the first source operand is a register. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@319231 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 3e43049 commit 9bc5c88

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,12 @@ bool AArch64InstrInfo::areMemAccessesTriviallyDisjoint(
940940
bool AArch64InstrInfo::analyzeCompare(const MachineInstr &MI, unsigned &SrcReg,
941941
unsigned &SrcReg2, int &CmpMask,
942942
int &CmpValue) const {
943+
// The first operand can be a frame index where we'd normally expect a
944+
// register.
945+
assert(MI.getNumOperands() >= 2 && "All AArch64 cmps should have 2 operands");
946+
if (!MI.getOperand(1).isReg())
947+
return false;
948+
943949
switch (MI.getOpcode()) {
944950
default:
945951
break;

lib/Target/AArch64/AArch64RedundantCopyElimination.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ AArch64RedundantCopyElimination::knownRegValInBlock(
167167
// CMP is an alias for SUBS with a dead destination register.
168168
case AArch64::SUBSWri:
169169
case AArch64::SUBSXri: {
170+
// Sometimes the first operand is a FrameIndex. Bail if tht happens.
171+
if (!PredI.getOperand(1).isReg())
172+
return None;
170173
MCPhysReg SrcReg = PredI.getOperand(1).getReg();
171174

172175
// Must not be a symbolic immediate.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; RUN: llc -mtriple=aarch64 %s -o - | FileCheck %s
2+
3+
; CHECK: test_frameindex_cmp:
4+
; CHECK: cmn sp, #{{[0-9]+}}
5+
define void @test_frameindex_cmp() {
6+
%stack = alloca i8
7+
%stack.int = ptrtoint i8* %stack to i64
8+
%cmp = icmp ne i64 %stack.int, 0
9+
br i1 %cmp, label %bb1, label %bb2
10+
11+
bb1:
12+
call void @bar()
13+
ret void
14+
15+
bb2:
16+
ret void
17+
}
18+
19+
declare void @bar()

0 commit comments

Comments
 (0)