[llvm] 29661fe - [InstCombine] add tests for logical-and / logical-or folds; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 13:47:53 PDT 2022
Author: Sanjay Patel
Date: 2022-11-01T16:47:41-04:00
New Revision: 29661fe94bf12ced1f99c80914c3c87ba4198ab4
URL: https://github.com/llvm/llvm-project/commit/29661fe94bf12ced1f99c80914c3c87ba4198ab4
DIFF: https://github.com/llvm/llvm-project/commit/29661fe94bf12ced1f99c80914c3c87ba4198ab4.diff
LOG: [InstCombine] add tests for logical-and / logical-or folds; NFC
Added:
Modified:
llvm/test/Transforms/InstCombine/select-safe-transforms.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/select-safe-transforms.ll b/llvm/test/Transforms/InstCombine/select-safe-transforms.ll
index df21dd525701..7263edcf60ac 100644
--- a/llvm/test/Transforms/InstCombine/select-safe-transforms.ll
+++ b/llvm/test/Transforms/InstCombine/select-safe-transforms.ll
@@ -144,6 +144,40 @@ define i1 @and_orn_cmp_1_logical(i32 %a, i32 %b, i1 %y) {
ret i1 %and
}
+define i1 @and_orn_cmp_1_partial_logical(i32 %a, i32 %b, i1 %y) {
+; CHECK-LABEL: @and_orn_cmp_1_partial_logical(
+; CHECK-NEXT: [[X:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i32 [[A]], [[B]]
+; CHECK-NEXT: [[OR:%.*]] = or i1 [[X_INV]], [[Y:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[X]], i1 [[OR]], i1 false
+; CHECK-NEXT: ret i1 [[AND]]
+;
+ %x = icmp sgt i32 %a, %b
+ %x_inv = icmp sle i32 %a, %b
+ %or = or i1 %x_inv, %y
+ %and = select i1 %x, i1 %or, i1 false
+ ret i1 %and
+}
+
+define i1 @and_orn_cmp_1_partial_logical_commute(i32 %a, i32 %b) {
+; CHECK-LABEL: @and_orn_cmp_1_partial_logical_commute(
+; CHECK-NEXT: [[Y:%.*]] = call i1 @gen1()
+; CHECK-NEXT: [[X:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i32 [[A]], [[B]]
+; CHECK-NEXT: [[OR:%.*]] = or i1 [[Y]], [[X_INV]]
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[X]], i1 [[OR]], i1 false
+; CHECK-NEXT: ret i1 [[AND]]
+;
+ %y = call i1 @gen1() ; thwart complexity-based canonicalization
+ %x = icmp sgt i32 %a, %b
+ %x_inv = icmp sle i32 %a, %b
+ %or = or i1 %y, %x_inv
+ %and = select i1 %x, i1 %or, i1 false
+ ret i1 %and
+}
+
+; TODO: This does not require poison-safe (select) logical-and.
+
define i1 @andn_or_cmp_2_logical(i16 %a, i16 %b, i1 %y) {
; CHECK-LABEL: @andn_or_cmp_2_logical(
; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
@@ -157,6 +191,47 @@ define i1 @andn_or_cmp_2_logical(i16 %a, i16 %b, i1 %y) {
ret i1 %and
}
+define i1 @andn_or_cmp_2_partial_logical(i16 %a, i16 %b, i1 %y) {
+; CHECK-LABEL: @andn_or_cmp_2_partial_logical(
+; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i1 [[X_INV]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[AND]]
+;
+ %x = icmp sge i16 %a, %b
+ %x_inv = icmp slt i16 %a, %b
+ %or = or i1 %x, %y
+ %and = select i1 %or, i1 %x_inv, i1 false
+ ret i1 %and
+}
+
+define i1 @andn_or_cmp_2_partial_logical_commute(i16 %a, i16 %b) {
+; CHECK-LABEL: @andn_or_cmp_2_partial_logical_commute(
+; CHECK-NEXT: [[Y:%.*]] = call i1 @gen1()
+; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[AND:%.*]] = and i1 [[Y]], [[X_INV]]
+; CHECK-NEXT: ret i1 [[AND]]
+;
+ %y = call i1 @gen1() ; thwart complexity-based canonicalization
+ %x = icmp sge i16 %a, %b
+ %x_inv = icmp slt i16 %a, %b
+ %or = or i1 %y, %x
+ %and = select i1 %or, i1 %x_inv, i1 false
+ ret i1 %and
+}
+
+define <2 x i1> @not_logical_or2(i1 %b, <2 x i32> %a) {
+; CHECK-LABEL: @not_logical_or2(
+; CHECK-NEXT: [[COND:%.*]] = icmp ult <2 x i32> [[A:%.*]], <i32 3, i32 3>
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[B:%.*]], <2 x i1> [[COND]], <2 x i1> zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[AND]]
+;
+ %cond = icmp ult <2 x i32> %a, <i32 3, i32 3>
+ %implied = icmp slt <2 x i32> %a, <i32 -1, i32 -1>
+ %or = select i1 %b, <2 x i1> <i1 true, i1 true>, <2 x i1> %implied
+ %and = select <2 x i1> %or, <2 x i1> %cond, <2 x i1> zeroinitializer
+ ret <2 x i1> %and
+}
+
define i1 @bools_logical_commute0(i1 %a, i1 %b, i1 %c) {
; CHECK-LABEL: @bools_logical_commute0(
; CHECK-NEXT: [[OR:%.*]] = select i1 [[C:%.*]], i1 [[B:%.*]], i1 [[A:%.*]]
@@ -589,6 +664,23 @@ define i1 @orn_and_cmp_1_logical(i37 %a, i37 %b, i1 %y) {
ret i1 %or
}
+define i1 @orn_and_cmp_1_partial_logical(i37 %a, i37 %b, i1 %y) {
+; CHECK-LABEL: @orn_and_cmp_1_partial_logical(
+; CHECK-NEXT: [[X:%.*]] = icmp sgt i37 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i37 [[A]], [[B]]
+; CHECK-NEXT: [[AND:%.*]] = and i1 [[X]], [[Y:%.*]]
+; CHECK-NEXT: [[OR:%.*]] = select i1 [[X_INV]], i1 true, i1 [[AND]]
+; CHECK-NEXT: ret i1 [[OR]]
+;
+ %x = icmp sgt i37 %a, %b
+ %x_inv = icmp sle i37 %a, %b
+ %and = and i1 %y, %x
+ %or = select i1 %x_inv, i1 true, i1 %and
+ ret i1 %or
+}
+
+; TODO: This does not require poison-safe (select) logical-or.
+
define i1 @orn_and_cmp_2_logical(i16 %a, i16 %b, i1 %y) {
; CHECK-LABEL: @orn_and_cmp_2_logical(
; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
@@ -601,3 +693,16 @@ define i1 @orn_and_cmp_2_logical(i16 %a, i16 %b, i1 %y) {
%or = select i1 %and, i1 true, i1 %x_inv
ret i1 %or
}
+
+define i1 @orn_and_cmp_2_partial_logical(i16 %a, i16 %b, i1 %y) {
+; CHECK-LABEL: @orn_and_cmp_2_partial_logical(
+; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[OR:%.*]] = or i1 [[X_INV]], [[Y:%.*]]
+; CHECK-NEXT: ret i1 [[OR]]
+;
+ %x = icmp sge i16 %a, %b
+ %x_inv = icmp slt i16 %a, %b
+ %and = and i1 %y, %x
+ %or = select i1 %and, i1 true, i1 %x_inv
+ ret i1 %or
+}
More information about the llvm-commits
mailing list