[llvm] [SDAG] Select _, X, X -> X (PR #173989)

via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 30 06:19:27 PST 2025


https://github.com/DaKnig created https://github.com/llvm/llvm-project/pull/173989

The code was simplified a tad. No tests since I am not sure that it would even catch any real case this deep into the functions.

>From 17e43a0d9b74389065605fab70fddd41ae583308 Mon Sep 17 00:00:00 2001
From: DaKnig <37626476+DaKnig at users.noreply.github.com>
Date: Tue, 30 Dec 2025 16:14:31 +0200
Subject: [PATCH] [SDAG] Select _, X, X -> X

---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 74d00317c3649..f75b797abef19 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -13383,11 +13383,9 @@ static SDValue combineVSelectWithAllOnesOrZeros(SDValue Cond, SDValue TVal,
   if (!IsTAllZero && !IsTAllOne && !IsFAllZero && !IsFAllOne)
     return SDValue();
 
-  // select Cond, 0, 0 → 0
-  if (IsTAllZero && IsFAllZero) {
-    return VT.isFloatingPoint() ? DAG.getConstantFP(0.0, DL, VT)
-                                : DAG.getConstant(0, DL, VT);
-  }
+  // select Cond, X, X → X
+  if (TVal == FVal)
+    return TVal;
 
   // check select(setgt lhs, -1), 1, -1 --> or (sra lhs, bitwidth - 1), 1
   APInt TValAPInt;



More information about the llvm-commits mailing list