[PATCH] [InstCombine] mark ADD with nuw if no unsigned overflow

Jingyue Wu jingyue at google.com
Sat Jun 14 14:36:26 PDT 2014


Thanks for your review! I agree with your concerns. computeKnownBits is a little expensive. I'm considering merging WillNotOverflowSignedAdd and WillNotOverflowUnsignedAdd in a separate patch.

================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:1264
@@ -1246,1 +1263,3 @@
   }
+  if (!I.hasNoUnsignedWrap() && WillNotOverflowUnsignedAdd(LHS, RHS)) {
+    Changed = true;
----------------
Chandler Carruth wrote:
> This should be an else if, no? If we succeed at adding NSW, why would we check for NUW?
Even with nsw, there's still value of checking for NUW. e.g., "add i16 16383, 16383" can be marked with both nsw and nuw, while "add i16 65535, 65535" can be marked with only nsw but not nuw.

http://reviews.llvm.org/D4144






More information about the llvm-commits mailing list