summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 7faf19fd72f..04ccc77b6bb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -585,7 +585,7 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,
break;
case ISD::ZERO_EXTEND:
if (Operand.getValueType() == VT) return Operand; // noop extension
- if (OpOpcode == ISD::ZERO_EXTEND)
+ if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x)
return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0));
break;
case ISD::TRUNCATE:
@@ -1025,6 +1025,18 @@ SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT,SDOperand N1,
return N1;
}
+ // If we are extending the result of a setcc, and we already know the
+ // contents of the top bits, eliminate the extension.
+ if (N1.getOpcode() == ISD::SETCC)
+ switch (TLI.getSetCCResultContents()) {
+ case TargetLowering::UndefinedSetCCResult: break;
+ case TargetLowering::ZeroOrOneSetCCResult:
+ if (Opcode == ISD::ZERO_EXTEND_INREG) return N1;
+ break;
+ case TargetLowering::ZeroOrNegativeOneSetCCResult:
+ if (Opcode == ISD::SIGN_EXTEND_INREG) return N1;
+ break;
+ }
break;
}
OpenPOWER on IntegriCloud