summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-02-17 01:29:24 +0000
committerChris Lattner <sabre@nondot.org>2011-02-17 01:29:24 +0000
commit3eb0af94c4062fa42519a8bc46d14ac64fb8fbc5 (patch)
tree4a8e096f1088d49bd32aa509c115f79b1c72b0d5
parent05d389f407d039f65d6e16e2002e9620550636fc (diff)
downloadbcm5719-llvm-3eb0af94c4062fa42519a8bc46d14ac64fb8fbc5.tar.gz
bcm5719-llvm-3eb0af94c4062fa42519a8bc46d14ac64fb8fbc5.zip
fix PR9215, preventing -reassociate from clearing nsw/nuw when
it swaps the LHS/RHS of a single binop. llvm-svn: 125700
-rw-r--r--llvm/lib/Transforms/Scalar/Reassociate.cpp7
-rw-r--r--llvm/test/Transforms/Reassociate/optional-flags.ll7
2 files changed, 11 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp
index 5df6f3725a3..e093b52571a 100644
--- a/llvm/lib/Transforms/Scalar/Reassociate.cpp
+++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp
@@ -348,9 +348,10 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
I->setOperand(0, Ops[i].Op);
I->setOperand(1, Ops[i+1].Op);
- // Conservatively clear all the optional flags, which may not hold
- // after the reassociation.
- I->clearSubclassOptionalData();
+ // Clear all the optional flags, which may not hold after the
+ // reassociation if the expression involved more than just this operation.
+ if (Ops.size() != 2)
+ I->clearSubclassOptionalData();
DEBUG(dbgs() << "TO: " << *I << '\n');
MadeChange = true;
diff --git a/llvm/test/Transforms/Reassociate/optional-flags.ll b/llvm/test/Transforms/Reassociate/optional-flags.ll
index 5ecc7675f8e..40f7d5bf5b8 100644
--- a/llvm/test/Transforms/Reassociate/optional-flags.ll
+++ b/llvm/test/Transforms/Reassociate/optional-flags.ll
@@ -20,3 +20,10 @@ define i64 @test1(i64 %a, i64 %b, i64 %c) {
%z = add nsw i64 %y, %a
ret i64 %z
}
+
+; PR9215
+; CHECK: %s = add nsw i32 %y, %x
+define i32 @test2(i32 %x, i32 %y) {
+ %s = add nsw i32 %x, %y
+ ret i32 %s
+}
OpenPOWER on IntegriCloud