[PATCH] [Reassociate] Better preserve NSW/NUW flags. (PR12985)

Chad Rosier mcrosier at codeaurora.org
Fri Nov 7 12:56:20 PST 2014


================
Comment at: lib/Transforms/Scalar/Reassociate.cpp:1039-1045
@@ +1038,9 @@
+
+  // 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 (NUW)
+    Mul->setHasNoSignedWrap(NSW);
+  Mul->setHasNoUnsignedWrap(NUW);
----------------
majnemer wrote:
> Shouldn't this be:
>   if (NSW && NUW)
> 
> ?
The logic is the same, but in the case that NSW is false it will avoid the call to the ineffectual setHasNoSignedWrap.

I'll fix this..  thanks!

http://reviews.llvm.org/D6172






More information about the llvm-commits mailing list