From c6fdb1de47bd5f26868838c37fa9e8cc1ac484bf Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sat, 16 Apr 2022 14:08:04 -0700 Subject: [PATCH] [X86] Move some hasOneUse checks after checking what the opcode is. Calling hasOneUse can be expensive on nodes with multiple results. Especially when some results are Chains. By checking the opcode first, we can avoid walking the uses if it isn't an interesting node, and thus avoid calling hasOneUse on a node that might have many uses. Found by profiling the IR given in D123857. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D123881 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index f02e59d..3120cd5 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -48883,9 +48883,10 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG, } // Try to fold a VTRUNCUS or VTRUNCS into a truncating store. - if (!St->isTruncatingStore() && StoredVal.hasOneUse() && + if (!St->isTruncatingStore() && (StoredVal.getOpcode() == X86ISD::VTRUNCUS || StoredVal.getOpcode() == X86ISD::VTRUNCS) && + StoredVal.hasOneUse() && TLI.isTruncStoreLegal(StoredVal.getOperand(0).getValueType(), VT)) { bool IsSigned = StoredVal.getOpcode() == X86ISD::VTRUNCS; return EmitTruncSStore(IsSigned, St->getChain(), @@ -48894,15 +48895,15 @@ static SDValue combineStore(SDNode *N, SelectionDAG &DAG, } // Try to fold a extract_element(VTRUNC) pattern into a truncating store. - if (!St->isTruncatingStore() && StoredVal.hasOneUse()) { + if (!St->isTruncatingStore()) { auto IsExtractedElement = [](SDValue V) { - if (V.getOpcode() == ISD::TRUNCATE && V.getOperand(0).hasOneUse()) + if (V.getOpcode() == ISD::TRUNCATE && V.hasOneUse()) V = V.getOperand(0); unsigned Opc = V.getOpcode(); - if (Opc == ISD::EXTRACT_VECTOR_ELT || Opc == X86ISD::PEXTRW) { - if (V.getOperand(0).hasOneUse() && isNullConstant(V.getOperand(1))) - return V.getOperand(0); - } + if ((Opc == ISD::EXTRACT_VECTOR_ELT || Opc == X86ISD::PEXTRW) && + isNullConstant(V.getOperand(1)) && V.hasOneUse() && + V.getOperand(0).hasOneUse()) + return V.getOperand(0); return SDValue(); }; if (SDValue Extract = IsExtractedElement(StoredVal)) { -- 2.7.4