[llvm] cd6858c - [InstCombine] Add tests for folding `(icmp eq/ne (and X, -P2), INT_MIN)`; NFC
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 3 11:05:21 PDT 2024
Author: Noah Goldstein
Date: 2024-10-03T13:05:08-05:00
New Revision: cd6858c74ee76f3270d39f110a31ef1b8852695f
URL: https://github.com/llvm/llvm-project/commit/cd6858c74ee76f3270d39f110a31ef1b8852695f
DIFF: https://github.com/llvm/llvm-project/commit/cd6858c74ee76f3270d39f110a31ef1b8852695f.diff
LOG: [InstCombine] Add tests for folding `(icmp eq/ne (and X, -P2), INT_MIN)`; NFC
Added:
llvm/test/Transforms/InstCombine/icmp-signmask.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/icmp-signmask.ll b/llvm/test/Transforms/InstCombine/icmp-signmask.ll
new file mode 100644
index 00000000000000..bea8da2074ab0b
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/icmp-signmask.ll
@@ -0,0 +1,57 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+define i1 @cmp_x_and_negp2_with_eq(i8 %x) {
+; CHECK-LABEL: @cmp_x_and_negp2_with_eq(
+; CHECK-NEXT: [[ANDX:%.*]] = and i8 [[X:%.*]], -2
+; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ANDX]], -128
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %andx = and i8 %x, -2
+ %r = icmp eq i8 %andx, 128
+ ret i1 %r
+}
+
+define i1 @cmp_x_and_negp2_with_eq_fail_not_signmask(i8 %x) {
+; CHECK-LABEL: @cmp_x_and_negp2_with_eq_fail_not_signmask(
+; CHECK-NEXT: [[ANDX:%.*]] = and i8 [[X:%.*]], -2
+; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[ANDX]], -124
+; CHECK-NEXT: ret i1 [[R]]
+;
+ %andx = and i8 %x, -2
+ %r = icmp eq i8 %andx, 132
+ ret i1 %r
+}
+
+define <2 x i1> @cmp_x_and_negp2_with_ne(<2 x i8> %x) {
+; CHECK-LABEL: @cmp_x_and_negp2_with_ne(
+; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 -8, i8 -16>
+; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], <i8 -128, i8 -128>
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %andx = and <2 x i8> %x, <i8 -8, i8 -16>
+ %r = icmp ne <2 x i8> %andx, <i8 128, i8 128>
+ ret <2 x i1> %r
+}
+
+define <2 x i1> @cmp_x_and_negp2_with_ne_or_z(<2 x i8> %x) {
+; CHECK-LABEL: @cmp_x_and_negp2_with_ne_or_z(
+; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 0, i8 -16>
+; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], <i8 -128, i8 -128>
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %andx = and <2 x i8> %x, <i8 0, i8 -16>
+ %r = icmp ne <2 x i8> %andx, <i8 128, i8 128>
+ ret <2 x i1> %r
+}
+
+define <2 x i1> @cmp_x_and_negp2_with_ne_fail_not_p2(<2 x i8> %x) {
+; CHECK-LABEL: @cmp_x_and_negp2_with_ne_fail_not_p2(
+; CHECK-NEXT: [[ANDX:%.*]] = and <2 x i8> [[X:%.*]], <i8 -8, i8 -15>
+; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i8> [[ANDX]], <i8 -128, i8 -128>
+; CHECK-NEXT: ret <2 x i1> [[R]]
+;
+ %andx = and <2 x i8> %x, <i8 -8, i8 -15>
+ %r = icmp ne <2 x i8> %andx, <i8 128, i8 128>
+ ret <2 x i1> %r
+}
More information about the llvm-commits
mailing list