[llvm] [DAG][X86] Do not narrow trunc(select) to a type undesirable for SELECT (PR #223763)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 05:33:25 PDT 2026


=?utf-8?q?Paweł?= Bylica <pawel at hepcolgum.band>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/223763 at github.com>


================
@@ -17788,8 +17772,15 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
   }
 
   // trunc (select c, a, b) -> select c, (trunc a), (trunc b)
+  // Do not narrow to a legal type the target considers undesirable for a
+  // select (e.g. i8 on X86, which has no 8-bit CMOV and would widen it again),
+  // unless both select operands are constants: then no truncate of a computed
+  // value is introduced and the narrow select is never worse.
   if (N0.getOpcode() == ISD::SELECT && N0.hasOneUse() &&
-      TLI.isTruncateFree(SrcVT, VT)) {
+      TLI.isTruncateFree(SrcVT, VT) &&
+      (!TLI.isTypeLegal(VT) || TLI.isTypeDesirableForOp(ISD::SELECT, VT) ||
----------------
RKSimon wrote:

why the `!TLI.isTypeLegal(VT)` case?

https://github.com/llvm/llvm-project/pull/223763


More information about the llvm-commits mailing list