[DAG] Add trunc(select) narrowing tests (NFC) (#248034)
DAGCombiner::visitTRUNCATE narrows trunc(select c, a, b) to
select c, (trunc a), (trunc b) when truncating is free. These tests pin
its current output for #223763, which stops it for i8 on X86 with CMOV.
All test IR is what opt -O2 produces for x86-64, s390x and amdgcn with
their real datalayouts, so it is IR the backend can see. InstCombine
already narrows a trunc of a select with a constant arm, so that case
only comes from truncates the DAG creates, here a shift amount.
X86 (x86-64, i686 with and without CMOV):
- trunc_select_i8: computed arms of an i32 select truncated to i8. With
CMOV, LowerSELECT widens the i8 select with a MOVZX of each arm
computed in i8.
- trunc_select_i32: an i64 select truncated to i32, which has a CMOV of
its own width.
- trunc_select_i7: an illegal type, legalized to i8.
- trunc_select_shift_amount: a select of two constant shift amounts,
which the DAG truncates to i8.
- trunc_select_extracts, trunc_select_shifted_loads: arms whose
narrowing enables other folds, one PEXTRW per arm with SSE2 and one
load of a selected address.
SystemZ and AMDGPU: selects narrowed to illegal vector types,
<2 x i32> and <4 x i8>.
The existing tests that #223763 changes keep their IR: they are
regression tests whose IR is deliberate.
Split out of #223763, with the IR rewritten as opt -O2 output.
Assisted-by: Claude Code (Claude Opus 5.5)