diff options
author | Chris Lattner <sabre@nondot.org> | 2005-04-12 02:19:10 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-04-12 02:19:10 +0000 |
commit | 5b95ed652fcfe578aa8af4e21318fca989164e21 (patch) | |
tree | b1791d6b9cf62d61986587863e5b69e1b482b49c | |
parent | 08b698e38db5ab5db44c0472e2a7f4f780887629 (diff) |
Emit comparisons against the sign bit better. Codegen this:
bool %test1(long %X) {
%A = setlt long %X, 0
ret bool %A
}
like this:
test1:
cmpl $0, 8(%esp)
setl %al
movzbl %al, %eax
ret
instead of:
test1:
movl 8(%esp), %ecx
cmpl $0, %ecx
setl %al
movzbw %al, %ax
cmpl $0, 4(%esp)
setb %dl
movzbw %dl, %dx
cmpl $0, %ecx
cmove %dx, %ax
movzbl %al, %eax
ret
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21243 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 3bd2494ceaa..7965e141a54 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -768,6 +768,16 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { DAG.getConstant(0, Tmp1.getValueType())); break; default: + // If this is a comparison of the sign bit, just look at the top part. + // X > -1, x < 0 + if (ConstantSDNode *CST = dyn_cast<ConstantSDNode>(Node->getOperand(1))) + if ((cast<SetCCSDNode>(Node)->getCondition() == ISD::SETLT && + CST->getValue() == 0) || // X < 0 + (cast<SetCCSDNode>(Node)->getCondition() == ISD::SETGT && + (CST->isAllOnesValue()))) // X > -1 + return DAG.getSetCC(cast<SetCCSDNode>(Node)->getCondition(), + Node->getValueType(0), LHSHi, RHSHi); + // FIXME: This generated code sucks. ISD::CondCode LowCC; switch (cast<SetCCSDNode>(Node)->getCondition()) { |