[llvm] [InstCombine] Extend `foldICmpAddConstant` to disjoint `or`. (PR #75899)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 20:46:27 PST 2024
================
@@ -5138,3 +5137,63 @@ entry:
%cmp = icmp eq i8 %add2, %add1
ret i1 %cmp
}
+
+define i1 @icmp_disjoint_or_sgt(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_sgt(
+; CHECK-NEXT: [[C:%.*]] = icmp sgt i32 [[X:%.*]], 35
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 6
+ %C = icmp sgt i32 %or_, 41
+ ret i1 %C
+}
+
+define i1 @icmp_disjoint_or_slt(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_slt(
+; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[X:%.*]], 35
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 6
+ %C = icmp slt i32 %or_, 41
+ ret i1 %C
+}
+
+define i1 @icmp_disjoint_or_ult(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_ult(
+; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[X:%.*]], 35
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 6
+ %C = icmp ult i32 %or_, 41
+ ret i1 %C
+}
+
+define i1 @icmp_disjoint_or_ugt(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_ugt(
+; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[X:%.*]], 35
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 6
+ %C = icmp ugt i32 %or_, 41
+ ret i1 %C
+}
+
+define i1 @icmp_disjoint_or_eq(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_eq(
+; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[X:%.*]], 0
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 5
+ %C = icmp eq i32 %or_, 5
+ ret i1 %C
+}
+
+define i1 @icmp_disjoint_or_be(i32 %x) {
+; CHECK-LABEL: @icmp_disjoint_or_be(
+; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[X:%.*]], 0
+; CHECK-NEXT: ret i1 [[C]]
+;
+ %or_ = or disjoint i32 %x, 5
+ %C = icmp ne i32 %or_, 5
+ ret i1 %C
+}
----------------
dtcxzyw wrote:
Please also add some negative tests.
https://github.com/llvm/llvm-project/pull/75899
More information about the llvm-commits
mailing list