summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Analysis/InstructionSimplify.cpp48
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp6
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp12
3 files changed, 49 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 11e24e5e3e9..097b99eb0a5 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3556,14 +3556,53 @@ static bool IsIdempotent(Intrinsic::ID ID) {
}
template <typename IterTy>
-static Value *SimplifyIntrinsic(Intrinsic::ID IID, IterTy ArgBegin, IterTy ArgEnd,
+static Value *SimplifyIntrinsic(Function *F, IterTy ArgBegin, IterTy ArgEnd,
const Query &Q, unsigned MaxRecurse) {
+ Intrinsic::ID IID = F->getIntrinsicID();
+ unsigned NumOperands = std::distance(ArgBegin, ArgEnd);
+ Type *ReturnType = F->getReturnType();
+
+ // Binary Ops
+ if (NumOperands == 2) {
+ Value *LHS = *ArgBegin;
+ Value *RHS = *(ArgBegin + 1);
+ if (IID == Intrinsic::usub_with_overflow ||
+ IID == Intrinsic::ssub_with_overflow) {
+ // X - X -> { 0, false }
+ if (LHS == RHS)
+ return Constant::getNullValue(ReturnType);
+
+ // X - undef -> undef
+ // undef - X -> undef
+ if (isa<UndefValue>(LHS) || isa<UndefValue>(RHS))
+ return UndefValue::get(ReturnType);
+ }
+
+ if (IID == Intrinsic::uadd_with_overflow ||
+ IID == Intrinsic::sadd_with_overflow) {
+ // X + undef -> undef
+ if (isa<UndefValue>(RHS))
+ return UndefValue::get(ReturnType);
+ }
+
+ if (IID == Intrinsic::umul_with_overflow ||
+ IID == Intrinsic::smul_with_overflow) {
+ // X * 0 -> { 0, false }
+ if (match(RHS, m_Zero()))
+ return Constant::getNullValue(ReturnType);
+
+ // X * undef -> { 0, false }
+ if (match(RHS, m_Undef()))
+ return Constant::getNullValue(ReturnType);
+ }
+ }
+
// Perform idempotent optimizations
if (!IsIdempotent(IID))
return nullptr;
// Unary Ops
- if (std::distance(ArgBegin, ArgEnd) == 1)
+ if (NumOperands == 1)
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(*ArgBegin))
if (II->getIntrinsicID() == IID)
return II;
@@ -3587,9 +3626,8 @@ static Value *SimplifyCall(Value *V, IterTy ArgBegin, IterTy ArgEnd,
if (!F)
return nullptr;
- if (Intrinsic::ID IID = F->getIntrinsicID())
- if (Value *Ret =
- SimplifyIntrinsic(IID, ArgBegin, ArgEnd, Q, MaxRecurse))
+ if (F->isIntrinsic())
+ if (Value *Ret = SimplifyIntrinsic(F, ArgBegin, ArgEnd, Q, MaxRecurse))
return Ret;
if (!canConstantFoldCallTo(F))
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 3b925eda16b..e83b9dd36ae 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -13,6 +13,7 @@
#include "InstCombineInternal.h"
#include "llvm/ADT/Statistic.h"
+#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Dominators.h"
@@ -323,6 +324,11 @@ static Value *SimplifyX86vperm2(const IntrinsicInst &II,
/// the heavy lifting.
///
Instruction *InstCombiner::visitCallInst(CallInst &CI) {
+ auto Args = CI.arg_operands();
+ if (Value *V = SimplifyCall(CI.getCalledValue(), Args.begin(), Args.end(), DL,
+ TLI, DT, AC))
+ return ReplaceInstUsesWith(CI, V);
+
if (isFreeCall(&CI, TLI))
return visitFree(CI);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 09ab16511e7..2dafa58d305 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2139,10 +2139,6 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
}
// FALL THROUGH uadd into sadd
case OCF_SIGNED_ADD: {
- // X + undef -> undef
- if (isa<UndefValue>(RHS))
- return SetResult(RHS, UndefValue::get(Builder->getInt1Ty()), false);
-
// X + 0 -> {X, false}
if (match(RHS, m_Zero()))
return SetResult(LHS, Builder->getFalse(), false);
@@ -2157,14 +2153,6 @@ bool InstCombiner::OptimizeOverflowCheck(OverflowCheckFlavor OCF, Value *LHS,
case OCF_UNSIGNED_SUB:
case OCF_SIGNED_SUB: {
- // undef - X -> undef
- if (isa<UndefValue>(LHS))
- return SetResult(LHS, UndefValue::get(Builder->getInt1Ty()), false);
-
- // X - undef -> undef
- if (isa<UndefValue>(RHS))
- return SetResult(RHS, UndefValue::get(Builder->getInt1Ty()), false);
-
// X - 0 -> {X, false}
if (match(RHS, m_Zero()))
return SetResult(LHS, Builder->getFalse(), false);
OpenPOWER on IntegriCloud