[llvm] cf491a1 - Precommit test for D144777, NFC
Jun Zhang via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 26 20:25:36 PST 2023
Author: Jun Zhang
Date: 2023-02-27T12:23:18+08:00
New Revision: cf491a165f239abfa7ab9e707f5cbd1861a6cb20
URL: https://github.com/llvm/llvm-project/commit/cf491a165f239abfa7ab9e707f5cbd1861a6cb20
DIFF: https://github.com/llvm/llvm-project/commit/cf491a165f239abfa7ab9e707f5cbd1861a6cb20.diff
LOG: Precommit test for D144777, NFC
Signed-off-by: Jun Zhang <jun at junz.org>
Added:
llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll b/llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll
new file mode 100644
index 000000000000..8c512092a3dd
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/fold-signbit-test-power2.ll
@@ -0,0 +1,119 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; icmp slt (and X, -X), 0 --> icmp eq (X, MinSignC)
+define i1 @pow2_or_zero1(i8 %x) {
+; CHECK-LABEL: @pow2_or_zero1(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[POW2_OR_ZERO]], 0
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %neg = sub i8 0, %x
+ %pow2_or_zero = and i8 %x, %neg
+ %cmp = icmp slt i8 %pow2_or_zero, 0
+ ret i1 %cmp
+}
+
+; icmp slt (and -X, X), 0 --> icmp eq (X, MinSignC)
+define i1 @pow2_or_zero1_commute(i8 %A) {
+; CHECK-LABEL: @pow2_or_zero1_commute(
+; CHECK-NEXT: [[X:%.*]] = sdiv i8 42, [[A:%.*]]
+; CHECK-NEXT: [[NEG:%.*]] = sub nsw i8 0, [[X]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[X]], [[NEG]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[POW2_OR_ZERO]], 0
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %x = sdiv i8 42, %A ; thwart complexity-based canonicalization
+ %neg = sub i8 0, %x
+ %pow2_or_zero = and i8 %neg, %x
+ %cmp = icmp slt i8 %pow2_or_zero, 0
+ ret i1 %cmp
+}
+
+define <2 x i1> @pow2_or_zero1_vec(<2 x i8> %x) {
+; CHECK-LABEL: @pow2_or_zero1_vec(
+; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[NEG]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[POW2_OR_ZERO]], zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %neg = sub <2 x i8> <i8 0, i8 0>, %x
+ %pow2_or_zero = and <2 x i8> %x, %neg
+ %cmp = icmp slt <2 x i8> %pow2_or_zero, <i8 0, i8 0>
+ ret <2 x i1> %cmp
+}
+
+
+define <2 x i1> @pow2_or_zero1_vec_commute(<2 x i8> %A) {
+; CHECK-LABEL: @pow2_or_zero1_vec_commute(
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[A:%.*]], <i8 42, i8 42>
+; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[X]], [[NEG]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[POW2_OR_ZERO]], zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %x = mul <2 x i8> <i8 42, i8 42>, %A ; thwart complexity-based canonicalization
+ %neg = sub <2 x i8> <i8 0, i8 0>, %x
+ %pow2_or_zero = and <2 x i8> %neg, %x
+ %cmp = icmp slt <2 x i8> %pow2_or_zero, <i8 0, i8 0>
+ ret <2 x i1> %cmp
+}
+
+; icmp sgt (and X, -X), -1 --> icmp ne (X, MinSignC)
+define i1 @pow2_or_zero2(i8 %x) {
+; CHECK-LABEL: @pow2_or_zero2(
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X:%.*]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[NEG]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[POW2_OR_ZERO]], -1
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %neg = sub i8 0, %x
+ %pow2_or_zero = and i8 %x, %neg
+ %cmp = icmp sgt i8 %pow2_or_zero, -1
+ ret i1 %cmp
+}
+
+; icmp sgt (and -X, X), -1 --> icmp ne (X, MinSignC)
+define i1 @pow2_or_zero2_commute(i8 %A) {
+; CHECK-LABEL: @pow2_or_zero2_commute(
+; CHECK-NEXT: [[X:%.*]] = mul i8 [[A:%.*]], 42
+; CHECK-NEXT: [[NEG:%.*]] = sub i8 0, [[X]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and i8 [[X]], [[NEG]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[POW2_OR_ZERO]], -1
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %x = mul i8 42, %A ; thwart complexity-based canonicalization
+ %neg = sub i8 0, %x
+ %pow2_or_zero = and i8 %neg, %x
+ %cmp = icmp sgt i8 %pow2_or_zero, -1
+ ret i1 %cmp
+}
+
+define <2 x i1> @pow2_or_zero2_vec(<2 x i8> %x) {
+; CHECK-LABEL: @pow2_or_zero2_vec(
+; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[NEG]], [[X]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[POW2_OR_ZERO]], <i8 -1, i8 -1>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %neg = sub <2 x i8> <i8 0, i8 0>, %x
+ %pow2_or_zero = and <2 x i8> %x, %neg
+ %cmp = icmp sgt <2 x i8> %pow2_or_zero, <i8 -1, i8 -1>
+ ret <2 x i1> %cmp
+}
+
+define <2 x i1> @pow2_or_zero2_vec_commute(<2 x i8> %A) {
+; CHECK-LABEL: @pow2_or_zero2_vec_commute(
+; CHECK-NEXT: [[X:%.*]] = mul <2 x i8> [[A:%.*]], <i8 42, i8 42>
+; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X]]
+; CHECK-NEXT: [[POW2_OR_ZERO:%.*]] = and <2 x i8> [[X]], [[NEG]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i8> [[POW2_OR_ZERO]], <i8 -1, i8 -1>
+; CHECK-NEXT: ret <2 x i1> [[CMP]]
+;
+ %x = mul <2 x i8> <i8 42, i8 42>, %A ; thwart complexity-based canonicalization
+ %neg = sub <2 x i8> <i8 0, i8 0>, %x
+ %pow2_or_zero = and <2 x i8> %neg, %x
+ %cmp = icmp sgt <2 x i8> %pow2_or_zero, <i8 -1, i8 -1>
+ ret <2 x i1> %cmp
+}
More information about the llvm-commits
mailing list