summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChad Rosier <mcrosier@codeaurora.org>2014-11-07 22:12:57 +0000
committerChad Rosier <mcrosier@codeaurora.org>2014-11-07 22:12:57 +0000
commitb3eb452e83cf56d52081c969155208d979d106a1 (patch)
treede98ac55bb10d06d00a61774304782928961e556 /llvm/lib
parent89c5ad4cda7356a4da124c41f69fd3e002609681 (diff)
downloadbcm5719-llvm-b3eb452e83cf56d52081c969155208d979d106a1.tar.gz
bcm5719-llvm-b3eb452e83cf56d52081c969155208d979d106a1.zip
[Reassociate] Better preserve NSW/NUW flags.
Part of PR12985. Phabricator Revision: http://reviews.llvm.org/D6172 llvm-svn: 221555
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/Reassociate.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 02cf708311b..77e6a35119e 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -1031,8 +1031,19 @@ static BinaryOperator *ConvertShiftToMul(Instruction *Shl) {
BinaryOperator::CreateMul(Shl->getOperand(0), MulCst, "", Shl);
Shl->setOperand(0, UndefValue::get(Shl->getType())); // Drop use of op.
Mul->takeName(Shl);
+
+ // Everyone now refers to the mul instruction.
Shl->replaceAllUsesWith(Mul);
Mul->setDebugLoc(Shl->getDebugLoc());
+
+ // We can safely preserve the nuw flag in all cases. It's also safe to turn a
+ // nuw nsw shl into a nuw nsw mul. However, nsw in isolation requires special
+ // handling.
+ bool NSW = cast<BinaryOperator>(Shl)->hasNoSignedWrap();
+ bool NUW = cast<BinaryOperator>(Shl)->hasNoUnsignedWrap();
+ if (NSW && NUW)
+ Mul->setHasNoSignedWrap(true);
+ Mul->setHasNoUnsignedWrap(NUW);
return Mul;
}
OpenPOWER on IntegriCloud