diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-09-14 21:30:07 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-09-14 21:30:07 +0000 |
commit | 46945b9e9d86d66ae054c8ca6ad79b0cd0da8531 (patch) | |
tree | f3166dfce23ba750201e38e2b901953077c76dcc | |
parent | c68f78d5d86e4d3a2e69c5f1ed8d6a17f3e16233 (diff) | |
download | bcm5719-llvm-46945b9e9d86d66ae054c8ca6ad79b0cd0da8531.tar.gz bcm5719-llvm-46945b9e9d86d66ae054c8ca6ad79b0cd0da8531.zip |
[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.
llvm-svn: 342289
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineInternal.h | 18 |
2 files changed, 19 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index c0fd14b2644..838ef3a1c6a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1062,9 +1062,7 @@ Instruction *InstCombiner::narrowAddIfNoOverflow(BinaryOperator &I) { } // 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) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h index 228a61672f7..1462660a54d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -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); |