[llvm] [DAGCombiner] Fold `sub nuw C, x` -> `xor x, C` when C is a mask (PR #192692)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 17 09:16:52 PDT 2026
================
@@ -0,0 +1,74 @@
+; RUN: llc -mtriple=x86_64 < %s | FileCheck %s --check-prefix=X86
+
+define i8 @sub_nuw_mask_4bit(i8 %x) {
+; X86-LABEL: sub_nuw_mask_4bit:
+; X86: xorb $15, %al
+ %r = sub nuw i8 15, %x
+ ret i8 %r
+}
+
+define i8 @sub_nuw_mask_7bit(i8 %x) {
+; X86-LABEL: sub_nuw_mask_7bit:
+; X86: xorb $127, %al
+ %r = sub nuw i8 127, %x
+ ret i8 %r
+}
+
+define i8 @sub_nuw_allones_i8(i8 %x) {
+; X86-LABEL: sub_nuw_allones_i8:
+; X86: notb %al
+ %r = sub nuw i8 255, %x
+ ret i8 %r
+}
+
+define i16 @sub_nuw_mask_i16(i16 %x) {
+; X86-LABEL: sub_nuw_mask_i16:
+; X86: xorl $255, %eax
+ %r = sub nuw i16 255, %x
+ ret i16 %r
+}
+
+define i32 @sub_nuw_mask_i32(i32 %x) {
+; X86-LABEL: sub_nuw_mask_i32:
+; X86: xorl $65535, %eax
+ %r = sub nuw i32 65535, %x
+ ret i32 %r
+}
+
+define i8 @sub_nuw_nonmask(i8 %x) {
+; X86-LABEL: sub_nuw_nonmask:
+; X86-NOT: xorb
----------------
arsenm wrote:
-NOT checks aren't the most reliable thing to check, can you use update_llc_test_checks (and add nounwind to all the functions)
https://github.com/llvm/llvm-project/pull/192692
More information about the llvm-commits
mailing list