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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Tirthankar Mazumder (wermos)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/181555.diff


1 Files Affected:

- (modified) llvm/test/Transforms/InstCombine/icmp-add.ll (+22) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list