[all-commits] [llvm/llvm-project] db6aed: [DAG][X86] Do not narrow trunc(select) to a type u...

Paweł Bylica via All-commits all-commits at lists.llvm.org
Tue Sep 15 10:10:12 PDT 2026


  Branch: refs/heads/users/chfast/trunc-select-narrowing
  Home:   https://github.com/llvm/llvm-project
  Commit: db6aed4991dd68002ef31aac41a84dd0e3186383
      https://github.com/llvm/llvm-project/commit/db6aed4991dd68002ef31aac41a84dd0e3186383
  Author: Paweł Bylica <pawel at hepcolgum.band>
  Date:   2026-09-15 (Tue, 15 Sep 2026)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
    M llvm/lib/Target/X86/X86ISelLowering.cpp
    M llvm/test/CodeGen/X86/bit-manip-i128.ll
    M llvm/test/CodeGen/X86/freeze.ll
    M llvm/test/CodeGen/X86/lea-opt2.ll
    M llvm/test/CodeGen/X86/select.ll
    M llvm/test/CodeGen/X86/shl-crash-on-legalize.ll
    M llvm/test/CodeGen/X86/trunc-select-narrowing.ll

  Log Message:
  -----------
  [DAG][X86] Do not narrow trunc(select) to a type undesirable for SELECT

DAGCombiner rewrites trunc(select c, a, b) as select c, (trunc a), (trunc b)
whenever truncating is free. On X86 that fires for i8, and where CMOV is
available there is no 8-bit form of it, so LowerSELECT widens the narrow select
back to i32 through ANY_EXTENDs, which lower to MOVZX. The narrowing then only
buys a byte ALU chain plus a MOVZX for each operand that became an i8 op:

  orb     $64, %al        orl     $64, %eax
  movzbl  %al, %eax       cmovneq %rcx, %rax
  cmovnel %ecx, %eax

Gate the fold on isTypeDesirableForOp(ISD::SELECT, VT) and let X86 report i8 as
undesirable when it can use CMOV. Without CMOV the select lowers to a branch
instead, where i8 operands are fine, so narrowing stays enabled there. The hook
defaults to isTypeLegal(VT), so guarded by isTypeLegal it is a no-op for every
target that does not override it. A select of two constants stays exempt: it
introduces no truncate of a computed value, so the narrow form is never worse.

Assisted-by: Claude Code



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list