From 0c5d6ccbfc089b3335a78d910febff44c3dd622c Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 1 Dec 2018 10:58:34 +0000 Subject: [InstCombine] Support ssub.sat canonicalization for non-splats Extend ssub.sat(X, C) -> sadd.sat(X, -C) canonicalization to also support non-splat vector constants. This is done by generalizing the implementation of the isNotMinSignedValue() helper to return true for constants that are non-splat, but don't contain any signed min elements. Differential Revision: https://reviews.llvm.org/D55011 llvm-svn: 348072 --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp') diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index f0b09e1f0bd..a023b6da232 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2104,11 +2104,10 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } // ssub.sat(X, C) -> sadd.sat(X, -C) if C != MIN - // TODO: Support non-splat C. - const APInt *C; - if (IID == Intrinsic::ssub_sat && match(Arg1, m_APInt(C)) && - !C->isMinSignedValue()) { - Value *NegVal = ConstantInt::get(II->getType(), -*C); + Constant *C; + if (IID == Intrinsic::ssub_sat && match(Arg1, m_Constant(C)) && + C->isNotMinSignedValue()) { + Value *NegVal = ConstantExpr::getNeg(C); return replaceInstUsesWith( *II, Builder.CreateBinaryIntrinsic( Intrinsic::sadd_sat, Arg0, NegVal)); -- cgit v1.2.3