[llvm] [InstCombine] Remove `foldSPFofSPF` (PR #146736)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 08:55:45 PDT 2025
https://github.com/dtcxzyw created https://github.com/llvm/llvm-project/pull/146736
This fold should be covered by `foldMinMaxSharedOp/foldMinimumMaximumSharedOp`. And it has the same poison-propagation problem as https://github.com/llvm/llvm-project/issues/143120.
>From 8a0f7780f39e6a7f03886dd022a4f7cfa8a2e604 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Wed, 2 Jul 2025 23:50:01 +0800
Subject: [PATCH] [InstCombine] Remove `foldSPFofSPF`
---
.../InstCombine/InstCombineInternal.h | 3 --
.../InstCombine/InstCombineSelect.cpp | 32 -------------------
2 files changed, 35 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index 9adde8094d44d..65daeecba061e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -782,9 +782,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
Instruction *foldSelectEqualityTest(SelectInst &SI);
Instruction *foldSelectOpOp(SelectInst &SI, Instruction *TI, Instruction *FI);
Instruction *foldSelectIntoOp(SelectInst &SI, Value *, Value *);
- Instruction *foldSPFofSPF(Instruction *Inner, SelectPatternFlavor SPF1,
- Value *A, Value *B, Instruction &Outer,
- SelectPatternFlavor SPF2, Value *C);
Instruction *foldSelectInstWithICmp(SelectInst &SI, ICmpInst *ICI);
Value *foldSelectWithConstOpToBinOp(ICmpInst *Cmp, Value *TrueVal,
Value *FalseVal);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 73ba0f78e8053..5a0cd443b1701 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -2051,27 +2051,6 @@ Instruction *InstCombinerImpl::foldSelectInstWithICmp(SelectInst &SI,
return Changed ? &SI : nullptr;
}
-/// We have an SPF (e.g. a min or max) of an SPF of the form:
-/// SPF2(SPF1(A, B), C)
-Instruction *InstCombinerImpl::foldSPFofSPF(Instruction *Inner,
- SelectPatternFlavor SPF1, Value *A,
- Value *B, Instruction &Outer,
- SelectPatternFlavor SPF2,
- Value *C) {
- if (Outer.getType() != Inner->getType())
- return nullptr;
-
- if (C == A || C == B) {
- // MAX(MAX(A, B), B) -> MAX(A, B)
- // MIN(MIN(a, b), a) -> MIN(a, b)
- // TODO: This could be done in instsimplify.
- if (SPF1 == SPF2 && SelectPatternResult::isMinOrMax(SPF1))
- return replaceInstUsesWith(Outer, Inner);
- }
-
- return nullptr;
-}
-
/// Turn select C, (X + Y), (X - Y) --> (X + (select C, Y, (-Y))).
/// This is even legal for FP.
static Instruction *foldAddSubSelect(SelectInst &SI,
@@ -4157,17 +4136,6 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
Instruction::CastOps CastOp;
SelectPatternResult SPR = matchSelectPattern(&SI, LHS, RHS, &CastOp);
auto SPF = SPR.Flavor;
- if (SPF) {
- Value *LHS2, *RHS2;
- if (SelectPatternFlavor SPF2 = matchSelectPattern(LHS, LHS2, RHS2).Flavor)
- if (Instruction *R = foldSPFofSPF(cast<Instruction>(LHS), SPF2, LHS2,
- RHS2, SI, SPF, RHS))
- return R;
- if (SelectPatternFlavor SPF2 = matchSelectPattern(RHS, LHS2, RHS2).Flavor)
- if (Instruction *R = foldSPFofSPF(cast<Instruction>(RHS), SPF2, LHS2,
- RHS2, SI, SPF, LHS))
- return R;
- }
if (SelectPatternResult::isMinOrMax(SPF)) {
// Canonicalize so that
More information about the llvm-commits
mailing list