[InstSimplify] Handle some overflow intrinsics in InstSimplify

This change does a few things:
- Move some InstCombine transforms to InstSimplify
- Run SimplifyCall from within InstCombine::visitCallInst
- Teach InstSimplify to fold [us]mul_with_overflow(X, undef) to 0.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237995 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Majnemer
2015-05-22 03:56:46 +00:00
parent edcdc5cb6a
commit fe0d65bcc6
5 changed files with 75 additions and 19 deletions

View File

@@ -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);

View File

@@ -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);