From 42fcf79f36c07f30827087bcbf3f04d0a45ac2f8 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 5 Mar 2015 18:50:12 +0000 Subject: [PATCH] X86: Optimize address mode matching for FRAME_ALLOC_RECOVER nodes We know that the absolute symbol will be less than 2GB and thus will always fit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231389 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp | 1 + lib/Target/X86/X86ISelDAGToDAG.cpp | 9 +++++++++ test/CodeGen/X86/frameescape.ll | 8 ++++---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp index 17eff944c62..5898da41c7f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -95,6 +95,7 @@ std::string SDNode::getOperationName(const SelectionDAG *G) const { case ISD::GLOBAL_OFFSET_TABLE: return "GLOBAL_OFFSET_TABLE"; case ISD::RETURNADDR: return "RETURNADDR"; case ISD::FRAMEADDR: return "FRAMEADDR"; + case ISD::FRAME_ALLOC_RECOVER: return "FRAME_ALLOC_RECOVER"; case ISD::READ_REGISTER: return "READ_REGISTER"; case ISD::WRITE_REGISTER: return "WRITE_REGISTER"; case ISD::FRAME_TO_ARGS_OFFSET: return "FRAME_TO_ARGS_OFFSET"; diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index 8d50ae1584e..42715562a7c 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -1004,6 +1004,15 @@ bool X86DAGToDAGISel::MatchAddressRecursively(SDValue N, X86ISelAddressMode &AM, switch (N.getOpcode()) { default: break; + case ISD::FRAME_ALLOC_RECOVER: { + if (!AM.hasSymbolicDisplacement()) + if (const auto *ESNode = dyn_cast(N.getOperand(0))) + if (ESNode->getOpcode() == ISD::TargetExternalSymbol) { + AM.ES = ESNode->getSymbol(); + return false; + } + break; + } case ISD::Constant: { uint64_t Val = cast(N)->getSExtValue(); if (!FoldOffsetIntoAddress(Val, AM)) diff --git a/test/CodeGen/X86/frameescape.ll b/test/CodeGen/X86/frameescape.ll index 621dbe2d276..b48672d3808 100644 --- a/test/CodeGen/X86/frameescape.ll +++ b/test/CodeGen/X86/frameescape.ll @@ -16,20 +16,20 @@ define void @print_framealloc_from_fp(i8* %fp) { %b = bitcast i8* %b.i8 to i32* %b.val = load i32, i32* %b call i32 (i8*, ...)* @printf(i8* getelementptr ([10 x i8]* @str, i32 0, i32 0), i32 %b.val) + store i32 42, i32* %b ret void } ; CHECK-LABEL: print_framealloc_from_fp: ; CHECK: movq %rcx, %[[parent_fp:[a-z]+]] -; CHECK: movabsq $.Lalloc_func$frame_escape_0, %[[offs:[a-z]+]] -; CHECK: movl (%[[parent_fp]],%[[offs]]), %edx +; CHECK: movl .Lalloc_func$frame_escape_0(%[[parent_fp]]), %edx ; CHECK: leaq {{.*}}(%rip), %[[str:[a-z]+]] ; CHECK: movq %[[str]], %rcx ; CHECK: callq printf -; CHECK: movabsq $.Lalloc_func$frame_escape_1, %[[offs:[a-z]+]] -; CHECK: movl (%[[parent_fp]],%[[offs]]), %edx +; CHECK: movl .Lalloc_func$frame_escape_1(%[[parent_fp]]), %edx ; CHECK: movq %[[str]], %rcx ; CHECK: callq printf +; CHECK: movl $42, .Lalloc_func$frame_escape_1(%[[parent_fp]]) ; CHECK: retq define void @alloc_func() {