[PATCH] D41505: [DAG] Teach findBaseOffset to interpret indexes of indexed memory operations
Nirav Dave via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 3 07:53:58 PST 2018
niravd updated this revision to Diff 128524.
niravd retitled this revision from "[DAG] Teach BaseIndexOffset to correctly deal with with indexed operations" to "[DAG] Teach findBaseOffset to interpret indexes of indexed memory operations".
niravd edited the summary of this revision.
niravd added a comment.
Factored out the indexed memory operation correctness check into D417101.
https://reviews.llvm.org/D41505
Files:
llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
llvm/test/CodeGen/AArch64/arm64-abi-varargs.ll
llvm/test/CodeGen/AArch64/swifterror.ll
Index: llvm/test/CodeGen/AArch64/swifterror.ll
===================================================================
--- llvm/test/CodeGen/AArch64/swifterror.ll
+++ llvm/test/CodeGen/AArch64/swifterror.ll
@@ -316,12 +316,11 @@
; 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
Index: llvm/test/CodeGen/AArch64/arm64-abi-varargs.ll
===================================================================
--- llvm/test/CodeGen/AArch64/arm64-abi-varargs.ll
+++ llvm/test/CodeGen/AArch64/arm64-abi-varargs.ll
@@ -13,9 +13,8 @@
; 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
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAGAddressAnalysis.cpp
@@ -96,16 +96,43 @@
}
// 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());
+ if (LSBase->isIndexed() &&
+ Base.getResNo() == (LSBase->getNumValues() - 2))
+ 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41505.128524.patch
Type: text/x-patch
Size: 3257 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180103/00f73c8a/attachment.bin>
More information about the llvm-commits
mailing list