summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2015-10-22 19:57:25 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2015-10-22 19:57:25 +0000
commita060e602fd6afa836f17da5b7fc865651714d259 (patch)
tree6ad3f2891b61f7ec9f81aca13d19726bafa94af9 /llvm/lib/Analysis
parent8f27415c05bda94861b01ddf97f288c3fbac5abe (diff)
downloadbcm5719-llvm-a060e602fd6afa836f17da5b7fc865651714d259.tar.gz
bcm5719-llvm-a060e602fd6afa836f17da5b7fc865651714d259.zip
[SCEV] Commute sign extends through nsw additions
Summary: Depends on D13613. Reviewers: atrick, hfinkel, reames, nlewycky Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D13685 llvm-svn: 251049
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 8a257b46e7e..c5ca839e474 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1631,6 +1631,16 @@ const SCEV *ScalarEvolution::getSignExtendExpr(const SCEV *Op,
}
}
}
+
+ // sext((A + B + ...)<nsw>) --> (sext(A) + sext(B) + ...)<nsw>
+ if (SA->getNoWrapFlags(SCEV::FlagNSW)) {
+ // If the addition does not sign overflow then we can, by definition,
+ // commute the sign extension with the addition operation.
+ SmallVector<const SCEV *, 4> Ops;
+ for (const auto *Op : SA->operands())
+ Ops.push_back(getSignExtendExpr(Op, Ty));
+ return getAddExpr(Ops, SCEV::FlagNSW);
+ }
}
// If the input value is a chrec scev, and we can prove that the value
// did not overflow the old, smaller, value, we can sign extend all of the
OpenPOWER on IntegriCloud