diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-05-21 09:22:06 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-05-21 09:22:06 +0000 |
commit | 691731eb9c1bffedcb29b3c8391010b8edab6abf (patch) | |
tree | 5b6eb75bc3c295b3b5bcf2d497b160e651b1f645 /llvm/lib | |
parent | 627c14a0684c00be0a40e942bb96bc30962844ae (diff) | |
download | bcm5719-llvm-691731eb9c1bffedcb29b3c8391010b8edab6abf.tar.gz bcm5719-llvm-691731eb9c1bffedcb29b3c8391010b8edab6abf.zip |
InstCombine: Turn mul.with.overflow(X, 2) into the cheaper add.with.overflow(X, X)
llvm-svn: 131789
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 243937705ac..ea0ffd9c340 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -535,6 +535,20 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { Constant *Struct = ConstantStruct::get(II->getContext(), V, 2, false); return InsertValueInst::Create(Struct, II->getArgOperand(0), 0); } + + // [su]mul.with.overflow(X, 2) -> [su]add.with.overflow(X, X) + if (RHSI->equalsInt(2)) { + Intrinsic::ID Add = + II->getIntrinsicID() == Intrinsic::smul_with_overflow ? + Intrinsic::sadd_with_overflow : Intrinsic::uadd_with_overflow; + + Module *M = II->getParent()->getParent()->getParent(); + const Type *Ty = RHSI->getType(); + Function *F = Intrinsic::getDeclaration(M, Add, &Ty, 1); + + Value *Ops[] = { II->getArgOperand(0), II->getArgOperand(0) }; + return CallInst::Create(F, Ops, Ops+2); + } } break; case Intrinsic::ppc_altivec_lvx: |