From ec03e0cd3b6d98a621d515dbb032ae799d273388 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 26 Jan 2009 18:43:34 +0000 Subject: [PATCH] Enhance logic in X86DAGToDAGISel::PreprocessForRMW which move load inside callseq_start to allow it to be folded into a call. It was not considering the cases where a token factor is between the load and the callseq_start. llvm-svn: 63022 --- lib/Target/X86/X86ISelDAGToDAG.cpp | 35 +++++++++++++++++------ test/CodeGen/X86/fold-call-3.ll | 45 ++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 test/CodeGen/X86/fold-call-3.ll diff --git a/lib/Target/X86/X86ISelDAGToDAG.cpp b/lib/Target/X86/X86ISelDAGToDAG.cpp index c1d886c32f5..04ba430d2d6 100644 --- a/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -432,14 +432,27 @@ static bool isRMWLoad(SDValue N, SDValue Chain, SDValue Address, /// MoveBelowCallSeqStart - Replace CALLSEQ_START operand with load's chain /// operand and move load below the call's chain operand. static void MoveBelowCallSeqStart(SelectionDAG *CurDAG, SDValue Load, - SDValue Call, SDValue Chain) { + SDValue Call, SDValue CallSeqStart) { SmallVector Ops; - for (unsigned i = 0, e = Chain.getNode()->getNumOperands(); i != e; ++i) - if (Load.getNode() == Chain.getOperand(i).getNode()) - Ops.push_back(Load.getOperand(0)); - else - Ops.push_back(Chain.getOperand(i)); - CurDAG->UpdateNodeOperands(Chain, &Ops[0], Ops.size()); + SDValue Chain = CallSeqStart.getOperand(0); + if (Chain.getNode() == Load.getNode()) + Ops.push_back(Load.getOperand(0)); + else { + assert(Chain.getOpcode() == ISD::TokenFactor && + "Unexpected CallSeqStart chain operand"); + for (unsigned i = 0, e = Chain.getNumOperands(); i != e; ++i) + if (Chain.getOperand(i).getNode() == Load.getNode()) + Ops.push_back(Load.getOperand(0)); + else + Ops.push_back(Chain.getOperand(i)); + SDValue NewChain = + CurDAG->getNode(ISD::TokenFactor, MVT::Other, &Ops[0], Ops.size()); + Ops.clear(); + Ops.push_back(NewChain); + } + for (unsigned i = 1, e = CallSeqStart.getNumOperands(); i != e; ++i) + Ops.push_back(CallSeqStart.getOperand(i)); + CurDAG->UpdateNodeOperands(CallSeqStart, &Ops[0], Ops.size()); CurDAG->UpdateNodeOperands(Load, Call.getOperand(0), Load.getOperand(1), Load.getOperand(2)); Ops.clear(); @@ -468,7 +481,13 @@ static bool isCalleeLoad(SDValue Callee, SDValue &Chain) { return false; Chain = Chain.getOperand(0); } - return Chain.getOperand(0).getNode() == Callee.getNode(); + + if (Chain.getOperand(0).getNode() == Callee.getNode()) + return true; + if (Chain.getOperand(0).getOpcode() == ISD::TokenFactor && + Callee.getValue(1).isOperandOf(Chain.getOperand(0).getNode())) + return true; + return false; } diff --git a/test/CodeGen/X86/fold-call-3.ll b/test/CodeGen/X86/fold-call-3.ll new file mode 100644 index 00000000000..824ae003da2 --- /dev/null +++ b/test/CodeGen/X86/fold-call-3.ll @@ -0,0 +1,45 @@ +; RUN: llvm-as < %s | llc -mtriple=x86_64-apple-darwin | grep call | grep 560 +; rdar://6522427 + + %"struct.clang::Action" = type { %"struct.clang::ActionBase" } + %"struct.clang::ActionBase" = type { i32 (...)** } + %"struct.clang::ActionBase::ActionResult<0u>" = type { i8*, i8 } +@NumTrials = internal global i32 10000000 ; [#uses=2] +@llvm.used = appending global [1 x i8*] [ i8* bitcast (void (i8*, %"struct.clang::Action"*)* @_Z25RawPointerPerformanceTestPvRN5clang6ActionE to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0] + +define void @_Z25RawPointerPerformanceTestPvRN5clang6ActionE(i8* %Val, %"struct.clang::Action"* %Actions) nounwind { +entry: + %0 = alloca %"struct.clang::ActionBase::ActionResult<0u>", align 8 ; <%"struct.clang::ActionBase::ActionResult<0u>"*> [#uses=3] + %1 = load i32* @NumTrials, align 4 ; [#uses=1] + %2 = icmp eq i32 %1, 0 ; [#uses=1] + br i1 %2, label %return, label %bb.nph + +bb.nph: ; preds = %entry + %3 = getelementptr %"struct.clang::Action"* %Actions, i64 0, i32 0, i32 0 ; [#uses=1] + %mrv_gep = bitcast %"struct.clang::ActionBase::ActionResult<0u>"* %0 to i64* ; [#uses=1] + %mrv_gep1 = getelementptr %"struct.clang::ActionBase::ActionResult<0u>"* %0, i64 0, i32 1 ; [#uses=1] + %4 = bitcast i8* %mrv_gep1 to i64* ; [#uses=1] + %5 = getelementptr %"struct.clang::ActionBase::ActionResult<0u>"* %0, i64 0, i32 0 ; [#uses=1] + br label %bb + +bb: ; preds = %bb, %bb.nph + %Trial.01 = phi i32 [ 0, %bb.nph ], [ %12, %bb ] ; [#uses=1] + %Val_addr.02 = phi i8* [ %Val, %bb.nph ], [ %11, %bb ] ; [#uses=1] + %6 = load i32 (...)*** %3, align 8 ; [#uses=1] + %7 = getelementptr i32 (...)** %6, i64 70 ; [#uses=1] + %8 = load i32 (...)** %7, align 8 ; [#uses=1] + %9 = bitcast i32 (...)* %8 to { i64, i64 } (%"struct.clang::Action"*, i8*)* ; <{ i64, i64 } (%"struct.clang::Action"*, i8*)*> [#uses=1] + %10 = call { i64, i64 } %9(%"struct.clang::Action"* %Actions, i8* %Val_addr.02) nounwind ; <{ i64, i64 }> [#uses=2] + %mrv_gr = extractvalue { i64, i64 } %10, 0 ; [#uses=1] + store i64 %mrv_gr, i64* %mrv_gep + %mrv_gr2 = extractvalue { i64, i64 } %10, 1 ; [#uses=1] + store i64 %mrv_gr2, i64* %4 + %11 = load i8** %5, align 8 ; [#uses=1] + %12 = add i32 %Trial.01, 1 ; [#uses=2] + %13 = load i32* @NumTrials, align 4 ; [#uses=1] + %14 = icmp ult i32 %12, %13 ; [#uses=1] + br i1 %14, label %bb, label %return + +return: ; preds = %bb, %entry + ret void +}