summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ScalarEvolution.cpp
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2018-06-11 18:57:58 +0000
committerJustin Lebar <jlebar@google.com>2018-06-11 18:57:58 +0000
commit4da41c13a5ed8dcec3fa945211e5da0286ecbe9e (patch)
treeabe8bd82dc392f5ba9669fb0cd51910a5f16543c /llvm/lib/Analysis/ScalarEvolution.cpp
parentaa4fec94d8a143c3487a45c2472a5d77325dd02c (diff)
downloadbcm5719-llvm-4da41c13a5ed8dcec3fa945211e5da0286ecbe9e.tar.gz
bcm5719-llvm-4da41c13a5ed8dcec3fa945211e5da0286ecbe9e.zip
[SCEV] Add transform zext((A * B * ...)<nuw>) --> (zext(A) * zext(B) * ...)<nuw>.
Reviewers: sanjoy Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D48041 llvm-svn: 334429
Diffstat (limited to 'llvm/lib/Analysis/ScalarEvolution.cpp')
-rw-r--r--llvm/lib/Analysis/ScalarEvolution.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index dee35392692..08d5eff100f 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -1778,6 +1778,18 @@ ScalarEvolution::getZeroExtendExpr(const SCEV *Op, Type *Ty, unsigned Depth) {
}
}
+ if (auto *SA = dyn_cast<SCEVMulExpr>(Op)) {
+ // zext((A * B * ...)<nuw>) --> (zext(A) * zext(B) * ...)<nuw>
+ if (SA->hasNoUnsignedWrap()) {
+ // If the multiply does not unsign overflow then we can, by definition,
+ // commute the zero extension with the multiply operation.
+ SmallVector<const SCEV *, 4> Ops;
+ for (const auto *Op : SA->operands())
+ Ops.push_back(getZeroExtendExpr(Op, Ty, Depth + 1));
+ return getMulExpr(Ops, SCEV::FlagNUW, Depth + 1);
+ }
+ }
+
// The cast wasn't folded; create an explicit cast node.
// Recompute the insert position, as it may have been invalidated.
if (const SCEV *S = UniqueSCEVs.FindNodeOrInsertPos(ID, IP)) return S;
OpenPOWER on IntegriCloud