diff options
| author | QingShan Zhang <qshanz@cn.ibm.com> | 2019-06-26 05:12:53 +0000 | 
|---|---|---|
| committer | QingShan Zhang <qshanz@cn.ibm.com> | 2019-06-26 05:12:53 +0000 | 
| commit | e0e7d4c3662e0263a05ba5207abec2faaf31ec76 (patch) | |
| tree | 4c78a55e170a0f9917b1e6f34ad97f573d02890b /llvm/lib/CodeGen/SelectionDAG | |
| parent | c3dfe9082bce468169c3ce94e55258d1bca7e692 (diff) | |
| download | bcm5719-llvm-e0e7d4c3662e0263a05ba5207abec2faaf31ec76.tar.gz bcm5719-llvm-e0e7d4c3662e0263a05ba5207abec2faaf31ec76.zip | |
Teach the DAGCombine to fold this pattern(c1 and c2 is constant).
// fold (sext (select cond, c1, c2)) -> (select cond, sext c1, sext c2)
// fold (zext (select cond, c1, c2)) -> (select cond, zext c1, zext c2)
// fold (aext (select cond, c1, c2)) -> (select cond, sext c1, sext c2)
Sign extend the operands if it is any_extend, to keep the signess of the operands that, the other combine rule would apply. The any_extend is handled as zero extend for constants. i.e.
t1: i8 = select t0, Constant:i8<-1>, Constant:i8<0>
t2: i64 = any_extend t1
 -->
t3: i64 = select t0, Constant:i64<-1>, Constant:i64<0>
 -->
t4: i64 = sign_extend_inreg t3
Differential Revision: https://reviews.llvm.org/D63318
llvm-svn: 364382
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 30 | 
1 files changed, 28 insertions, 2 deletions
| diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 06123487f50..3b480377dfc 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -8902,6 +8902,7 @@ static SDValue tryToFoldExtendOfConstant(SDNode *N, const TargetLowering &TLI,    unsigned Opcode = N->getOpcode();    SDValue N0 = N->getOperand(0);    EVT VT = N->getValueType(0); +  SDLoc DL(N);    assert((Opcode == ISD::SIGN_EXTEND || Opcode == ISD::ZERO_EXTEND ||           Opcode == ISD::ANY_EXTEND || Opcode == ISD::SIGN_EXTEND_VECTOR_INREG || @@ -8912,7 +8913,33 @@ static SDValue tryToFoldExtendOfConstant(SDNode *N, const TargetLowering &TLI,    // fold (zext c1) -> c1    // fold (aext c1) -> c1    if (isa<ConstantSDNode>(N0)) -    return DAG.getNode(Opcode, SDLoc(N), VT, N0); +    return DAG.getNode(Opcode, DL, VT, N0); + +  // fold (sext (select cond, c1, c2)) -> (select cond, sext c1, sext c2) +  // fold (zext (select cond, c1, c2)) -> (select cond, zext c1, zext c2) +  // fold (aext (select cond, c1, c2)) -> (select cond, sext c1, sext c2) +  if (N0->getOpcode() == ISD::SELECT) { +    SDValue Op1 = N0->getOperand(1); +    SDValue Op2 = N0->getOperand(2); +    if (isa<ConstantSDNode>(Op1) && isa<ConstantSDNode>(Op2) && +        (Opcode != ISD::ZERO_EXTEND || !TLI.isZExtFree(N0.getValueType(), VT))) { +      // For any_extend, choose sign extension of the constants to allow a +      // possible further transform to sign_extend_inreg.i.e. +      // +      // t1: i8 = select t0, Constant:i8<-1>, Constant:i8<0> +      // t2: i64 = any_extend t1 +      // --> +      // t3: i64 = select t0, Constant:i64<-1>, Constant:i64<0> +      // --> +      // t4: i64 = sign_extend_inreg t3 +      unsigned FoldOpc = Opcode; +      if (FoldOpc == ISD::ANY_EXTEND) +        FoldOpc = ISD::SIGN_EXTEND; +      return DAG.getSelect(DL, VT, N0->getOperand(0), +                           DAG.getNode(FoldOpc, DL, VT, Op1), +                           DAG.getNode(FoldOpc, DL, VT, Op2)); +    } +  }    // fold (sext (build_vector AllConstants) -> (build_vector AllConstants)    // fold (zext (build_vector AllConstants) -> (build_vector AllConstants) @@ -8927,7 +8954,6 @@ static SDValue tryToFoldExtendOfConstant(SDNode *N, const TargetLowering &TLI,    unsigned EVTBits = N0->getValueType(0).getScalarSizeInBits();    SmallVector<SDValue, 8> Elts;    unsigned NumElts = VT.getVectorNumElements(); -  SDLoc DL(N);    // For zero-extensions, UNDEF elements still guarantee to have the upper    // bits set to zero. | 

