diff options
| author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-04-22 18:47:44 +0000 | 
|---|---|---|
| committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-04-22 18:47:44 +0000 | 
| commit | 341c11da3bda1a3f877a3dc6e96f7d1f866f703f (patch) | |
| tree | 228b68cdcf3a22072f811465d3ab9fbcf8ab2523 /llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | |
| parent | ad45d911bb63141f0904b00c41a5f4f992f0ef33 (diff) | |
| download | llvm-341c11da3bda1a3f877a3dc6e96f7d1f866f703f.zip llvm-341c11da3bda1a3f877a3dc6e96f7d1f866f703f.tar.gz llvm-341c11da3bda1a3f877a3dc6e96f7d1f866f703f.tar.bz2  | |
DAGCombine: fold "(zext x) == C" into "x == (trunc C)" if the trunc is lossless.
On x86 this allows to fold a load into the cmp, greatly reducing register pressure.
  movzbl	(%rdi), %eax
  cmpl	$47, %eax
->
  cmpb	$47, (%rdi)
This shaves 8k off gcc.o on i386. I'll leave applying the patch in README.txt to Chris :)
llvm-svn: 130005
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 36 | 
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 843ed96..15606af 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -1916,6 +1916,42 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,        // TODO: (ctpop x) == 1 -> x && (x & x-1) == 0 iff ctpop is illegal.      } +    // (zext x) == C --> x == (trunc C) +    if (DCI.isBeforeLegalize() && N0->hasOneUse() && +        (Cond == ISD::SETEQ || Cond == ISD::SETNE)) { +      unsigned MinBits = N0.getValueSizeInBits(); +      SDValue PreZExt; +      if (N0->getOpcode() == ISD::ZERO_EXTEND) { +        // ZExt +        MinBits = N0->getOperand(0).getValueSizeInBits(); +        PreZExt = N0->getOperand(0); +      } else if (N0->getOpcode() == ISD::AND) { +        // DAGCombine turns costly ZExts into ANDs +        if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N0->getOperand(1))) +          if ((C->getAPIntValue()+1).isPowerOf2()) { +            MinBits = C->getAPIntValue().countTrailingOnes(); +            PreZExt = N0->getOperand(0); +          } +      } else if (LoadSDNode *LN0 = dyn_cast<LoadSDNode>(N0)) { +        // ZEXTLOAD +        if (LN0->getExtensionType() == ISD::ZEXTLOAD) { +          MinBits = LN0->getMemoryVT().getSizeInBits(); +          PreZExt = N0; +        } +      } + +      // Make sure we're not loosing bits from the constant. +      if (MinBits < C1.getBitWidth() && MinBits > C1.getActiveBits()) { +        EVT MinVT = EVT::getIntegerVT(*DAG.getContext(), MinBits); +        if (isTypeDesirableForOp(ISD::SETCC, MinVT)) { +          // Will get folded away. +          SDValue Trunc = DAG.getNode(ISD::TRUNCATE, dl, MinVT, PreZExt); +          SDValue C = DAG.getConstant(C1.trunc(MinBits), MinVT); +          return DAG.getSetCC(dl, VT, Trunc, C, Cond); +        } +      } +    } +      // If the LHS is '(and load, const)', the RHS is 0,      // the test is for equality or unsigned, and all 1 bits of the const are      // in the same partial word, see if we can shorten the load.  | 
