[llvm] [DAGCombiner] Fold `sub nuw C, x` -> `xor x, C` when C is a mask (PR #192692)

Madhur Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 10:03:14 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
----------------
MadhurKumar004 wrote:

I was trying to test for other backends, but you are right - its redundant on X86 architecture 

https://github.com/llvm/llvm-project/pull/192692


More information about the llvm-commits mailing list