From: Chris Lattner Date: Mon, 30 Jan 2006 04:34:44 +0000 (+0000) Subject: When lowering SELECT_CC, see if the input is a lowered SETCC. If so, fold X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=dea9528f7ffd838c333fa018ab7d2fa069db91dd;p=oota-llvm.git When lowering SELECT_CC, see if the input is a lowered SETCC. If so, fold the two operations together. This allows us to compile this: void %two(int %a, int* %b) { %tmp.2 = seteq int %a, 0 %tmp.0.0 = select bool %tmp.2, int 10, int 20 store int %tmp.0.0, int* %b ret void } into: two: save -96, %o6, %o6 or %g0, 20, %l0 or %g0, 10, %l1 subcc %i0, 0, %l2 be .LBBtwo_2 ! entry nop .LBBtwo_1: ! entry or %g0, %l0, %l1 .LBBtwo_2: ! entry st %l1, [%i1] restore %g0, %g0, %g0 retl nop instead of: two: save -96, %o6, %o6 sethi 0, %l0 or %g0, 1, %l1 or %g0, 20, %l2 or %g0, 10, %l3 subcc %i0, 0, %l4 be .LBBtwo_2 ! entry nop .LBBtwo_1: ! entry or %g0, %l0, %l1 .LBBtwo_2: ! entry subcc %l1, 0, %l0 bne .LBBtwo_4 ! entry nop .LBBtwo_3: ! entry or %g0, %l2, %l3 .LBBtwo_4: ! entry st %l3, [%i1] restore %g0, %g0, %g0 retl nop git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25806 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/lib/Target/Sparc/SparcISelDAGToDAG.cpp index a9c49506141..b02e8600b4e 100644 --- a/lib/Target/Sparc/SparcISelDAGToDAG.cpp +++ b/lib/Target/Sparc/SparcISelDAGToDAG.cpp @@ -669,6 +669,24 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) { SDOperand TrueVal = Op.getOperand(2); SDOperand FalseVal = Op.getOperand(3); + // If this is a select_cc of a "setcc", and if the setcc got lowered into + // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values. + if (isa(RHS) && cast(RHS)->getValue() == 0&& + CC == ISD::SETNE && + ((LHS.getOpcode() == V8ISD::SELECT_ICC && + LHS.getOperand(3).getOpcode() == V8ISD::CMPICC) || + (LHS.getOpcode() == V8ISD::SELECT_FCC && + LHS.getOperand(3).getOpcode() == V8ISD::CMPFCC)) && + isa(LHS.getOperand(0)) && + isa(LHS.getOperand(1)) && + cast(LHS.getOperand(0))->getValue() == 1 && + cast(LHS.getOperand(1))->getValue() == 0) { + SDOperand CMPCC = LHS.getOperand(3); + CC = cast(LHS.getOperand(2))->getValue(); + LHS = CMPCC.getOperand(0); + RHS = CMPCC.getOperand(1); + } + SDOperand CompareFlag; unsigned Opc; if (LHS.getValueType() == MVT::i32) { diff --git a/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp b/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp index a9c49506141..b02e8600b4e 100644 --- a/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp +++ b/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp @@ -669,6 +669,24 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) { SDOperand TrueVal = Op.getOperand(2); SDOperand FalseVal = Op.getOperand(3); + // If this is a select_cc of a "setcc", and if the setcc got lowered into + // an CMP[IF]CC/SELECT_[IF]CC pair, find the original compared values. + if (isa(RHS) && cast(RHS)->getValue() == 0&& + CC == ISD::SETNE && + ((LHS.getOpcode() == V8ISD::SELECT_ICC && + LHS.getOperand(3).getOpcode() == V8ISD::CMPICC) || + (LHS.getOpcode() == V8ISD::SELECT_FCC && + LHS.getOperand(3).getOpcode() == V8ISD::CMPFCC)) && + isa(LHS.getOperand(0)) && + isa(LHS.getOperand(1)) && + cast(LHS.getOperand(0))->getValue() == 1 && + cast(LHS.getOperand(1))->getValue() == 0) { + SDOperand CMPCC = LHS.getOperand(3); + CC = cast(LHS.getOperand(2))->getValue(); + LHS = CMPCC.getOperand(0); + RHS = CMPCC.getOperand(1); + } + SDOperand CompareFlag; unsigned Opc; if (LHS.getValueType() == MVT::i32) {