[llvm] ae117e1 - [InstCombine] remove dead code for add (select cond, (sub), 0); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 6 09:20:13 PDT 2022
Author: Sanjay Patel
Date: 2022-09-06T12:19:50-04:00
New Revision: ae117e1c1ba68da48c70f5cd8cb3c666fbdd1b77
URL: https://github.com/llvm/llvm-project/commit/ae117e1c1ba68da48c70f5cd8cb3c666fbdd1b77
DIFF: https://github.com/llvm/llvm-project/commit/ae117e1c1ba68da48c70f5cd8cb3c666fbdd1b77.diff
LOG: [InstCombine] remove dead code for add (select cond, (sub), 0); NFC
This pattern is handled more generally in SimplifySelectsFeedingBinaryOp().
Tests to confirm that added to the add.ll test file in the previous commit.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index c8b3fd05a8db..b80064b29878 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1378,31 +1378,6 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
return BinaryOperator::CreateOr(LHS, RHS);
- // add (select X 0 (sub n A)) A --> select X A n
- {
- SelectInst *SI = dyn_cast<SelectInst>(LHS);
- Value *A = RHS;
- if (!SI) {
- SI = dyn_cast<SelectInst>(RHS);
- A = LHS;
- }
- if (SI && SI->hasOneUse()) {
- Value *TV = SI->getTrueValue();
- Value *FV = SI->getFalseValue();
- Value *N;
-
- // Can we fold the add into the argument of the select?
- // We check both true and false select arguments for a matching subtract.
- if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N), m_Specific(A))))
- // Fold the add into the true select value.
- return SelectInst::Create(SI->getCondition(), N, A);
-
- if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N), m_Specific(A))))
- // Fold the add into the false select value.
- return SelectInst::Create(SI->getCondition(), A, N);
- }
- }
-
if (Instruction *Ext = narrowMathIfNoOverflow(I))
return Ext;
More information about the llvm-commits
mailing list