[llvm] [X86] combine-sub-usat.ll - add test coverage inspired by #170076 (PR #170681)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 08:05:51 PST 2025


https://github.com/RKSimon created https://github.com/llvm/llvm-project/pull/170681

None

>From 316a91a8d09f6b3b064862b5e77e8b276bb6a691 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Thu, 4 Dec 2025 16:04:56 +0000
Subject: [PATCH] [X86] combine-sub-usat.ll - add test coverage inspired by
 #170076

---
 llvm/test/CodeGen/X86/combine-sub-usat.ll | 27 +++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/llvm/test/CodeGen/X86/combine-sub-usat.ll b/llvm/test/CodeGen/X86/combine-sub-usat.ll
index 36e374bd2e67c..11eb363bb93f3 100644
--- a/llvm/test/CodeGen/X86/combine-sub-usat.ll
+++ b/llvm/test/CodeGen/X86/combine-sub-usat.ll
@@ -112,6 +112,33 @@ define <8 x i16> @combine_zero_v8i16(<8 x i16> %a0) {
   ret <8 x i16> %1
 }
 
+; fold (usub_sat x, 1) -> sub(x, zext(x != 0))
+define i32 @combine_dec_i32(i32 %a0) {
+; CHECK-LABEL: combine_dec_i32:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    xorl %eax, %eax
+; CHECK-NEXT:    subl $1, %edi
+; CHECK-NEXT:    cmovael %edi, %eax
+; CHECK-NEXT:    retq
+  %1 = call i32 @llvm.usub.sat.i32(i32 %a0, i32 1)
+  ret i32 %1
+}
+
+; fold (usub_sat x, 1) -> add(x, sext(x != 0))
+define <8 x i16> @combine_dec_v8i16(<8 x i16> %a0) {
+; SSE-LABEL: combine_dec_v8i16:
+; SSE:       # %bb.0:
+; SSE-NEXT:    psubusw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
+; SSE-NEXT:    retq
+;
+; AVX-LABEL: combine_dec_v8i16:
+; AVX:       # %bb.0:
+; AVX-NEXT:    vpsubusw {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
+; AVX-NEXT:    retq
+  %1 = call <8 x i16> @llvm.usub.sat.v8i16(<8 x i16> %a0, <8 x i16> splat (i16 1))
+  ret <8 x i16> %1
+}
+
 ; fold (usub_sat x, x) -> 0
 define i32 @combine_self_i32(i32 %a0) {
 ; CHECK-LABEL: combine_self_i32:



More information about the llvm-commits mailing list