summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorWeiming Zhao <weimingz@codeaurora.org>2016-07-29 23:33:48 +0000
committerWeiming Zhao <weimingz@codeaurora.org>2016-07-29 23:33:48 +0000
commit812fde3603490eb140eb3ef29341dfe0d4e43c66 (patch)
tree39708b6c117bb08a3a9c9bf4a9f334fd58ce2050 /llvm/lib
parent6ecbd16f008b7c18d871f5850dae30b0dc4889ed (diff)
downloadbcm5719-llvm-812fde3603490eb140eb3ef29341dfe0d4e43c66.tar.gz
bcm5719-llvm-812fde3603490eb140eb3ef29341dfe0d4e43c66.zip
DAG: avoid duplicated truncating for sign extended operand
Summary: When performing cmp for EQ/NE and the operand is sign extended, we can avoid the truncaton if the bits to be tested are no less than origianl bits. Reviewers: eli.friedman Subscribers: eli.friedman, aemerson, nemanjai, t.p.northover, llvm-commits Differential Revision: https://reviews.llvm.org/D22933 llvm-svn: 277252
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index 3ab9459c8af..020dac367b4 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -946,14 +946,16 @@ void DAGTypeLegalizer::PromoteSetCCOperands(SDValue &NewLHS,SDValue &NewRHS,
SDValue OpL = GetPromotedInteger(NewLHS);
SDValue OpR = GetPromotedInteger(NewRHS);
- // We would prefer to promote the comparison operand with sign extension,
- // if we find the operand is actually to truncate an AssertSext. With this
- // optimization, we can avoid inserting real truncate instruction, which
- // is redudant eventually.
- if (OpL->getOpcode() == ISD::AssertSext &&
- cast<VTSDNode>(OpL->getOperand(1))->getVT() == NewLHS.getValueType() &&
- OpR->getOpcode() == ISD::AssertSext &&
- cast<VTSDNode>(OpR->getOperand(1))->getVT() == NewRHS.getValueType()) {
+ // We would prefer to promote the comparison operand with sign extension.
+ // If the width of OpL/OpR excluding the duplicated sign bits is no greater
+ // than the width of NewLHS/NewRH, we can avoid inserting real truncate
+ // instruction, which is redudant eventually.
+ unsigned OpLEffectiveBits =
+ OpL.getValueType().getSizeInBits() - DAG.ComputeNumSignBits(OpL) + 1;
+ unsigned OpREffectiveBits =
+ OpR.getValueType().getSizeInBits() - DAG.ComputeNumSignBits(OpR) + 1;
+ if (OpLEffectiveBits <= NewLHS.getValueType().getSizeInBits() &&
+ OpREffectiveBits <= NewRHS.getValueType().getSizeInBits()) {
NewLHS = OpL;
NewRHS = OpR;
} else {
OpenPOWER on IntegriCloud