[llvm] 4b9d698 - [InstCombine][tests] add tests for signbit + logic; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 12 06:03:21 PDT 2021
Author: Sanjay Patel
Date: 2021-07-12T09:01:26-04:00
New Revision: 4b9d698243c4170e4ecf7f4336cd2824d2641e2a
URL: https://github.com/llvm/llvm-project/commit/4b9d698243c4170e4ecf7f4336cd2824d2641e2a
DIFF: https://github.com/llvm/llvm-project/commit/4b9d698243c4170e4ecf7f4336cd2824d2641e2a.diff
LOG: [InstCombine][tests] add tests for signbit + logic; NFC
PR50816
Added:
Modified:
llvm/test/Transforms/InstCombine/icmp.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll
index c64f2ac54cd15..30b6c88052b6e 100644
--- a/llvm/test/Transforms/InstCombine/icmp.ll
+++ b/llvm/test/Transforms/InstCombine/icmp.ll
@@ -3950,3 +3950,56 @@ define i1 @thread_cmp_over_select_with_poison_falseval(i1 %b) {
%tobool = icmp ne i32 %s, 0
ret i1 %tobool
}
+
+define i1 @signbit_true_logic(i8 %x) {
+; CHECK-LABEL: @signbit_true_logic(
+; CHECK-NEXT: [[DEC:%.*]] = add i8 [[X:%.*]], -1
+; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[X]], -1
+; CHECK-NEXT: [[AND:%.*]] = and i8 [[DEC]], [[NOT]]
+; CHECK-NEXT: [[R:%.*]] = icmp slt i8 [[AND]], 0
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %dec = add i8 %x, -1
+ %not = xor i8 %x, -1
+ %and = and i8 %dec, %not
+ %r = icmp slt i8 %and, 0
+ ret i1 %r
+}
+
+define <2 x i1> @signbit_false_logic(<2 x i5> %x) {
+; CHECK-LABEL: @signbit_false_logic(
+; CHECK-NEXT: [[DEC:%.*]] = add <2 x i5> [[X:%.*]], <i5 -1, i5 undef>
+; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i5> [[X]], <i5 -1, i5 -1>
+; CHECK-NEXT: [[AND:%.*]] = and <2 x i5> [[DEC]], [[NOT]]
+; CHECK-NEXT: [[R:%.*]] = icmp sgt <2 x i5> [[AND]], <i5 -1, i5 -1>
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %dec = add <2 x i5> %x, <i5 -1, i5 undef>
+ %not = xor <2 x i5> %x, <i5 -1, i5 -1>
+ %and = and <2 x i5> %dec, %not
+ %r = icmp sgt <2 x i5> %and, <i5 -1, i5 -1>
+ ret <2 x i1> %r
+}
+
+; Confirm that complexity canonicalization works for commuted pattern.
+
+define i1 @signbit_true_logic_uses_commute(i64 %x) {
+; CHECK-LABEL: @signbit_true_logic_uses_commute(
+; CHECK-NEXT: [[DEC:%.*]] = add i64 [[X:%.*]], -1
+; CHECK-NEXT: call void @use_i64(i64 [[DEC]])
+; CHECK-NEXT: [[NOT:%.*]] = xor i64 [[X]], -1
+; CHECK-NEXT: call void @use_i64(i64 [[NOT]])
+; CHECK-NEXT: [[AND:%.*]] = and i64 [[DEC]], [[NOT]]
+; CHECK-NEXT: call void @use_i64(i64 [[AND]])
+; CHECK-NEXT: [[R:%.*]] = icmp slt i64 [[AND]], 0
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %dec = add i64 %x, -1
+ call void @use_i64(i64 %dec)
+ %not = xor i64 %x, -1
+ call void @use_i64(i64 %not)
+ %and = and i64 %not, %dec
+ call void @use_i64(i64 %and)
+ %r = icmp slt i64 %and, 0
+ ret i1 %r
+}
More information about the llvm-commits
mailing list