[llvm] [InstCombine][NFC] Add test for existing fold (PR #181555)

Tirthankar Mazumder via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 15 07:41:21 PST 2026


https://github.com/wermos created https://github.com/llvm/llvm-project/pull/181555

Resolves #73417.

The fold described in #73417 is already present in LLVM `main`, but it isn't tested for specifically. This PR adds a test for this fold, based on the IR in the topmost comment of that issue.

>From 1fbfc02c29e49352ad10c7bedb882b4d77a6d914 Mon Sep 17 00:00:00 2001
From: Tirthankar Mazumder <tmazumder.github at gmail.com>
Date: Sun, 15 Feb 2026 21:07:29 +0530
Subject: [PATCH] Add test for a fold that is happening, but isn't specifically
 tested for.

---
 llvm/test/Transforms/InstCombine/icmp-add.ll | 22 ++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/llvm/test/Transforms/InstCombine/icmp-add.ll b/llvm/test/Transforms/InstCombine/icmp-add.ll
index 85d01b1786cc9..170ceb9f8ff08 100644
--- a/llvm/test/Transforms/InstCombine/icmp-add.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-add.ll
@@ -3579,3 +3579,25 @@ define i1 @icmp_ult_add_lshr_neg_no_nuw(i32 %arg0) {
   %v2 = icmp ult i32 %v1, 256
   ret i1 %v2
 }
+
+define i1 @fold-icmp-sum-of-extended-i1(i16 %0, i16 %1, i16 %2, i16 %3) {
+; CHECK-LABEL: @fold-icmp-sum-of-extended-i1(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[TMP4:%.*]] = icmp eq i16 [[TMP0:%.*]], [[TMP2:%.*]]
+; CHECK-NEXT:    [[_0:%.*]] = icmp ult i16 [[TMP1:%.*]], [[TMP3:%.*]]
+; CHECK-NEXT:    [[TMP5:%.*]] = icmp slt i16 [[TMP0]], [[TMP2]]
+; CHECK-NEXT:    [[_0_0:%.*]] = select i1 [[TMP4]], i1 [[_0]], i1 [[TMP5]]
+; CHECK-NEXT:    ret i1 [[_0_0]]
+;
+entry:
+  %lhs = icmp sgt i16 %0, %2
+  %rhs = icmp slt i16 %0, %2
+  %self1 = zext i1 %lhs to i8
+  %rhs2.neg = sext i1 %rhs to i8
+  %diff = add nsw i8 %rhs2.neg, %self1
+  %4 = icmp eq i8 %diff, 0
+  %_0 = icmp ult i16 %1, %3
+  %5 = icmp slt i8 %diff, 0
+  %_0.0 = select i1 %4, i1 %_0, i1 %5
+  ret i1 %_0.0
+}



More information about the llvm-commits mailing list