[llvm] r342289 - [InstCombine] add/use overflowing math helper functions; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 14 14:30:07 PDT 2018


Author: spatel
Date: Fri Sep 14 14:30:07 2018
New Revision: 342289

URL: http://llvm.org/viewvc/llvm-project?rev=342289&view=rev
Log:
[InstCombine] add/use overflowing math helper functions; NFC

The mul case can already be refactored to use this similar to
rL342278.
The sub case is proposed in D52075.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
    llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp?rev=342289&r1=342288&r2=342289&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAddSub.cpp Fri Sep 14 14:30:07 2018
@@ -1062,9 +1062,7 @@ Instruction *InstCombiner::narrowAddIfNo
   }
   // Both operands have narrow versions. Last step: the math must not overflow
   // in the narrow width.
-  bool WillNotOverflow = IsSext ? willNotOverflowSignedAdd(X, Y, I)
-                                : willNotOverflowUnsignedAdd(X, Y, I);
-  if (!WillNotOverflow)
+  if (!willNotOverflowAdd(X, Y, I, IsSext))
     return nullptr;
 
   // add (ext X), (ext Y) --> ext (add X, Y)

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h?rev=342289&r1=342288&r2=342289&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineInternal.h Fri Sep 14 14:30:07 2018
@@ -496,6 +496,12 @@ private:
            OverflowResult::NeverOverflows;
   }
 
+  bool willNotOverflowAdd(const Value *LHS, const Value *RHS,
+                          const Instruction &CxtI, bool IsSigned) const {
+    return IsSigned ? willNotOverflowSignedAdd(LHS, RHS, CxtI)
+                    : willNotOverflowUnsignedAdd(LHS, RHS, CxtI);
+  }
+
   bool willNotOverflowSignedSub(const Value *LHS, const Value *RHS,
                                 const Instruction &CxtI) const {
     return computeOverflowForSignedSub(LHS, RHS, &CxtI) ==
@@ -508,6 +514,12 @@ private:
            OverflowResult::NeverOverflows;
   }
 
+  bool willNotOverflowSub(const Value *LHS, const Value *RHS,
+                          const Instruction &CxtI, bool IsSigned) const {
+    return IsSigned ? willNotOverflowSignedSub(LHS, RHS, CxtI)
+                    : willNotOverflowUnsignedSub(LHS, RHS, CxtI);
+  }
+
   bool willNotOverflowSignedMul(const Value *LHS, const Value *RHS,
                                 const Instruction &CxtI) const {
     return computeOverflowForSignedMul(LHS, RHS, &CxtI) ==
@@ -520,6 +532,12 @@ private:
            OverflowResult::NeverOverflows;
   }
 
+  bool willNotOverflowMul(const Value *LHS, const Value *RHS,
+                          const Instruction &CxtI, bool IsSigned) const {
+    return IsSigned ? willNotOverflowSignedMul(LHS, RHS, CxtI)
+                    : willNotOverflowUnsignedMul(LHS, RHS, CxtI);
+  }
+
   Value *EmitGEPOffset(User *GEP);
   Instruction *scalarizePHI(ExtractElementInst &EI, PHINode *PN);
   Value *EvaluateInDifferentElementOrder(Value *V, ArrayRef<int> Mask);




More information about the llvm-commits mailing list