diff options
author | Ruhung <143302514+Ruhung@users.noreply.github.com> | 2025-01-12 23:51:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-12 16:51:58 +0100 |
commit | 4f7dc1b55ae5b8ed1a36dd941ef4f9920bfdac8d (patch) | |
tree | 38c75840888b1385af7df8bbdbb227ee246ad75b /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | 0d352b2ea767e043b47d78bfdbd6820356628314 (diff) | |
download | llvm-4f7dc1b55ae5b8ed1a36dd941ef4f9920bfdac8d.zip llvm-4f7dc1b55ae5b8ed1a36dd941ef4f9920bfdac8d.tar.gz llvm-4f7dc1b55ae5b8ed1a36dd941ef4f9920bfdac8d.tar.bz2 |
[InstCombine] Fold (add (add A, 1), (sext (icmp ne A, 0))) to call umax(A, 1) (#122491)
Transform (add (add A, 1), (sext (icmp ne A, 0))) into call umax(A, 1).
Fixes #121853.
Alive2: https://alive2.llvm.org/ce/z/TweTan
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index 73876d0..658bbbc 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -1775,6 +1775,15 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) { } } + // (add (add A, 1), (sext (icmp ne A, 0))) => call umax(A, 1) + if (match(LHS, m_Add(m_Value(A), m_One())) && + match(RHS, m_OneUse(m_SExt(m_OneUse(m_SpecificICmp( + ICmpInst::ICMP_NE, m_Specific(A), m_ZeroInt())))))) { + Value *OneConst = ConstantInt::get(A->getType(), 1); + Value *UMax = Builder.CreateBinaryIntrinsic(Intrinsic::umax, A, OneConst); + return replaceInstUsesWith(I, UMax); + } + if (Instruction *Ashr = foldAddToAshr(I)) return Ashr; |