[PATCH] D32686: [InstCombine][KnownBits] Use KnownBits better to detect nsw adds

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 30 20:53:10 PDT 2017


craig.topper added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:866
+  // there is no overflow to the sign bit.
+  if(RHSKnown.isNonNegative() || LHSKnown.isNonNegative()) {
+    APInt MaxRHS = ~RHSKnown.Zero;
----------------
Space between 'if' and 'parenthese'


================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:871
+    MaxLHS.clearSignBit();
+    APInt Result = MaxLHS + MaxRHS;
+    return Result.isSignBitClear();
----------------
Wrap both MaxLHS and MaxRHS in std::move so we can reuse one of their allocations to hold the addition result when dealing with larger than 64-bit numbers.


================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:880
+  // there is overflow to the sign bit.
+  if(RHSKnown.isNegative() || LHSKnown.isNegative()) {
+    APInt MinRHS = RHSKnown.One;
----------------
Space between 'if' and 'parenthese'


================
Comment at: lib/Transforms/InstCombine/InstCombineAddSub.cpp:885
+    MinLHS.clearSignBit();
+    APInt Result = MinLHS + MinRHS;
+    return Result.isSignBitSet();
----------------
Wrap both MinLHS and MinRHS in std::move so we can reuse one of their allocations to hold the addition result when dealing with larger than 64-bit numbers.


https://reviews.llvm.org/D32686





More information about the llvm-commits mailing list