Skip to content
This repository has been archived by the owner on Jan 17, 2019. It is now read-only.

Commit

Permalink
[DAG] Teach findBaseOffset to interpret indexes of indexed memory ope…
Browse files Browse the repository at this point in the history
…rations

Indexed outputs are addition / subtractions and can be interpreted as such.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@323539 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
niravhdave committed Jan 26, 2018
1 parent c9091f8 commit 3455380
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
43 changes: 35 additions & 8 deletions lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,43 @@ BaseIndexOffset BaseIndexOffset::match(LSBaseSDNode *N,
}

// Consume constant adds & ors with appropriate masking.
while (Base->getOpcode() == ISD::ADD || Base->getOpcode() == ISD::OR) {
if (auto *C = dyn_cast<ConstantSDNode>(Base->getOperand(1))) {
while (true) {
switch (Base->getOpcode()) {
case ISD::OR:
// Only consider ORs which act as adds.
if (Base->getOpcode() == ISD::OR &&
!DAG.MaskedValueIsZero(Base->getOperand(0), C->getAPIntValue()))
break;
Offset += C->getSExtValue();
Base = Base->getOperand(0);
continue;
if (auto *C = dyn_cast<ConstantSDNode>(Base->getOperand(1)))
if (DAG.MaskedValueIsZero(Base->getOperand(0), C->getAPIntValue())) {
Offset += C->getSExtValue();
Base = Base->getOperand(0);
continue;
}
break;
case ISD::ADD:
if (auto *C = dyn_cast<ConstantSDNode>(Base->getOperand(1))) {
Offset += C->getSExtValue();
Base = Base->getOperand(0);
continue;
}
break;
case ISD::LOAD:
case ISD::STORE: {
auto *LSBase = cast<LSBaseSDNode>(Base.getNode());
unsigned int IndexResNo = (Base->getOpcode() == ISD::LOAD) ? 1 : 0;
if (LSBase->isIndexed() && Base.getResNo() == IndexResNo)
if (auto *C = dyn_cast<ConstantSDNode>(LSBase->getOffset())) {
auto Off = C->getSExtValue();
if (LSBase->getAddressingMode() == ISD::PRE_DEC ||
LSBase->getAddressingMode() == ISD::POST_DEC)
Offset -= Off;
else
Offset += Off;
Base = LSBase->getBasePtr();
continue;
}
break;
}
}
// If we get here break out of the loop.
break;
}

Expand Down
3 changes: 1 addition & 2 deletions test/CodeGen/AArch64/arm64-abi-varargs.ll
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ define void @fn9(i32* %a1, i32 %a2, i32 %a3, i32 %a4, i32 %a5, i32 %a6, i32 %a7,
; CHECK: ldr {{w[0-9]+}}, [sp, #72]
; Second vararg
; CHECK: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8
; CHECK: add {{x[0-9]+}}, {{x[0-9]+}}, #8
; Third vararg
; CHECK: ldr {{w[0-9]+}}, [{{x[0-9]+}}]
; CHECK: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8
%1 = alloca i32, align 4
%2 = alloca i32, align 4
%3 = alloca i32, align 4
Expand Down
3 changes: 1 addition & 2 deletions test/CodeGen/AArch64/swifterror.ll
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,11 @@ define float @foo_vararg(%swift_error** swifterror %error_ptr_ref, ...) {
; First vararg
; CHECK-APPLE-DAG: orr {{x[0-9]+}}, [[ARGS]], #0x8
; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{.*}}[[TMP]], #16]
; CHECK-APPLE-DAG: add {{x[0-9]+}}, {{x[0-9]+}}, #8
; Second vararg
; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8
; CHECK-APPLE-DAG: add {{x[0-9]+}}, {{x[0-9]+}}, #16
; Third vararg
; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}]
; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8

; CHECK-APPLE: mov x21, x0
; CHECK-APPLE-NOT: x21
Expand Down

0 comments on commit 3455380

Please sign in to comment.