[llvm] [InstCombine] `A == MIN_INT ? B != MIN_INT : A < B` to `A < B` (PR #120177)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 18 06:26:50 PST 2024


================
@@ -0,0 +1,380 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i1 @compare_unsigned_min(i8 %0, i8 %1) {
+; CHECK-LABEL: define i1 @compare_unsigned_min(
+; CHECK-SAME: i8 [[TMP0:%.*]], i8 [[TMP1:%.*]]) {
+; CHECK-NEXT:  [[START:.*:]]
+; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i8 [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    ret i1 [[TMP2]]
+;
+start:
+  %2 = icmp eq i8 %0, 0
+  %3 = icmp ne i8 %1, 0
+  %4 = icmp ult i8 %0, %1
+  %result = select i1 %2, i1 %3, i1 %4
+  ret i1 %result
+}
----------------
dtcxzyw wrote:

Please use named values in tests.

```suggestion
define i1 @compare_unsigned_min(i8 %x, i8 %y) {
; CHECK-LABEL: define i1 @compare_unsigned_min(
; CHECK-SAME: i8 [[TMP0:%.*]], i8 [[TMP1:%.*]]) {
; CHECK-NEXT:  [[START:.*:]]
; CHECK-NEXT:    [[TMP2:%.*]] = icmp ult i8 [[TMP0]], [[TMP1]]
; CHECK-NEXT:    ret i1 [[TMP2]]
;
start:
  %cmp1 = icmp eq i8 %x, 0
  %cmp2 = icmp ne i8 %y, 0
  %cmp3 = icmp ult i8 %x, %1
  %result = select i1 %cmp1, i1 %cmp2, i1 %cmp3
  ret i1 %result
}
```

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


More information about the llvm-commits mailing list