[llvm-commits] [llvm] r125700 - in /llvm/trunk: lib/Transforms/Scalar/Reassociate.cpp test/Transforms/Reassociate/optional-flags.ll

Chris Lattner sabre at nondot.org
Wed Feb 16 17:29:24 PST 2011


Author: lattner
Date: Wed Feb 16 19:29:24 2011
New Revision: 125700

URL: http://llvm.org/viewvc/llvm-project?rev=125700&view=rev
Log:
fix PR9215, preventing -reassociate from clearing nsw/nuw when
it swaps the LHS/RHS of a single binop.

Modified:
    llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
    llvm/trunk/test/Transforms/Reassociate/optional-flags.ll

Modified: llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp?rev=125700&r1=125699&r2=125700&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/Reassociate.cpp Wed Feb 16 19:29:24 2011
@@ -348,9 +348,10 @@
       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;

Modified: llvm/trunk/test/Transforms/Reassociate/optional-flags.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Reassociate/optional-flags.ll?rev=125700&r1=125699&r2=125700&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Reassociate/optional-flags.ll (original)
+++ llvm/trunk/test/Transforms/Reassociate/optional-flags.ll Wed Feb 16 19:29:24 2011
@@ -20,3 +20,10 @@
   %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
+}





More information about the llvm-commits mailing list