llvm-project
9410b2c3 - [X86] Prefer AVX512 VPCMP against zero over splat(1) for sle/slt (#216716)

Commit
7 days ago
[X86] Prefer AVX512 VPCMP against zero over splat(1) for sle/slt (#216716) InstCombine canonicalizes `icmp sle x, 0` to `icmp slt x, 1`. AVX512 `VPCMP` can encode LE/GE against a zeroed register, but we were loading splat(1) from the constant pool (`vpcmpltb .LCPI`). ### Approach In `combineSetCC`, for AVX512 `vXi1` integer compares: - Rewrite `slt x, splat(1)` / `sgt splat(1), x` to `sle x, 0` - Rewrite `sgt x, splat(-1)` / `slt splat(-1), x` to `sge x, 0` - Skip the existing LE/GE → LT/GT `incDecVectorConstant` fold when it would replace a zero splat with ±1 (avoids oscillating with the rewrite above) This is the vector analog of scalar `TranslateX86CC` (`SETLT x, 1` → `COND_LE` vs 0). InstCombine is left unchanged. Pre-AVX512 (`-mcpu=x86-64-v3`) still uses `vpcmpgtb` vs zero + `not`. ## Test plan - [x] `llvm/test/CodeGen/X86/avx512-icmp-sle-zero.ll` — sle vs 0, slt vs 1, swapped sgt splat(1), sge vs 0, sgt vs -1; i8/i16/i32; ymm; x86-64-v3 and x86-64-v4 - [x] `llvm/test/CodeGen/X86/combine-icmp.ll` — `concat_icmp_v64i8_v32i8` now `vpxor` + `vpcmpleb` - [x] Existing AVX512 vec-cmp tests Fixes #216660
Author
Parents
Loading