[llvm] [InstCombine] Fold zext(icmp ne X, C) to X - C when X is in (C, C+1) (PR #208914)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 02:33:07 PDT 2026


================
@@ -1080,3 +1080,96 @@ define <2 x i8> @zext_or_trunc_nuw_vec(<2 x i8> %x, <2 x i4> %y) {
   %zext = zext <2 x i4> %or to <2 x i8>
   ret <2 x i8> %zext
 }
+
+; zext (X != CST) --> X - CST        if X in {CST, CST + 1}
+
+define i32 @zext_ne_lower_cst_sub(i32 range(i32 7, 9) %x) {
+; CHECK-LABEL: @zext_ne_lower_cst_sub(
+; CHECK-NEXT:    [[TMP2:%.*]] = add nsw i32 [[X:%.*]], -7
+; CHECK-NEXT:    ret i32 [[TMP2]]
+;
+  %1 = icmp ne i32 %x, 7
----------------
andjo403 wrote:

use named variables in all tests

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


More information about the llvm-commits mailing list