From 9bba894596bf658761c4f4feaa2532c5c3b6cfa0 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 26 Jan 2006 02:13:10 +0000 Subject: [PATCH] When trying to fold X86::SETCC into a Select, make a copy if it has more than one use. This allows more CMOV instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25634 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/X86/X86ISelLowering.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index cc713cf5ab8..067b88c9114 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -1669,9 +1669,17 @@ SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { // If the X86ISD::SETCC has more than one use, then it's probably better // to use a test instead of duplicating the X86ISD::CMP (for register // pressure reason). - // FIXME: Check number of live Op0 uses since we are in the middle of - // legalization process. - if (Op0.hasOneUse() && Op0.getOperand(1).getOpcode() == X86ISD::CMP) { + if (Op0.getOperand(1).getOpcode() == X86ISD::CMP) { + if (!Op0.hasOneUse()) { + std::vector Tys; + for (unsigned i = 0; i < Op0.Val->getNumValues(); ++i) + Tys.push_back(Op0.Val->getValueType(i)); + std::vector Ops; + for (unsigned i = 0; i < Op0.getNumOperands(); ++i) + Ops.push_back(Op0.getOperand(i)); + Op0 = DAG.getNode(X86ISD::SETCC, Tys, Ops); + } + CC = Op0.getOperand(0); Cond = Op0.getOperand(1); // Make a copy as flag result cannot be used by more than one. @@ -1720,9 +1728,17 @@ SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { // If the X86ISD::SETCC has more than one use, then it's probably better // to use a test instead of duplicating the X86ISD::CMP (for register // pressure reason). - // FIXME: Check number of live Cond uses since we are in the middle of - // legalization process. - if (Cond.hasOneUse() && Cond.getOperand(1).getOpcode() == X86ISD::CMP) { + if (Cond.getOperand(1).getOpcode() == X86ISD::CMP) { + if (!Cond.hasOneUse()) { + std::vector Tys; + for (unsigned i = 0; i < Cond.Val->getNumValues(); ++i) + Tys.push_back(Cond.Val->getValueType(i)); + std::vector Ops; + for (unsigned i = 0; i < Cond.getNumOperands(); ++i) + Ops.push_back(Cond.getOperand(i)); + Cond = DAG.getNode(X86ISD::SETCC, Tys, Ops); + } + CC = Cond.getOperand(0); Cond = Cond.getOperand(1); // Make a copy as flag result cannot be used by more than one.