[llvm] InstCombine/test: cover foldSelectValueEquivalence (PR #111694)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 14 12:05:10 PDT 2024
================
@@ -0,0 +1,311 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=instcombine -S %s | FileCheck %s
+
+define <2 x i8> @select_icmp_insertelement_eq(<2 x i8> %x, <2 x i8> %y, i8 %i) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_insertelement_eq(
+; CHECK-SAME: <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], i8 [[I:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[Y]], <i8 2, i8 2>
+; CHECK-NEXT: [[INSERT:%.*]] = insertelement <2 x i8> [[Y]], i8 0, i8 [[I]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[INSERT]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <2 x i8> %y, <i8 2, i8 2>
+ %insert = insertelement <2 x i8> %y, i8 0, i8 %i
+ %retval = select <2 x i1> %cmp, <2 x i8> %insert, <2 x i8> %x
+ ret <2 x i8> %retval
+}
+
+define <2 x i8> @select_icmp_insertelement_ne(<2 x i8> %x, <2 x i8> %y, i8 %i) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_insertelement_ne(
+; CHECK-SAME: <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]], i8 [[I:%.*]]) {
+; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq <2 x i8> [[Y]], <i8 2, i8 2>
+; CHECK-NEXT: [[INSERT:%.*]] = insertelement <2 x i8> [[Y]], i8 0, i8 [[I]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP_NOT]], <2 x i8> [[INSERT]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp ne <2 x i8> %y, <i8 2, i8 2>
+ %insert = insertelement <2 x i8> %y, i8 0, i8 %i
+ %retval = select <2 x i1> %cmp, <2 x i8> %x, <2 x i8> %insert
+ ret <2 x i8> %retval
+}
+
+define <2 x i8> @select_icmp_shufflevector_identity(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_shufflevector_identity(
+; CHECK-SAME: <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[Y]], <i8 2, i8 2>
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> <i8 2, i8 2>, <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <2 x i8> %y, <i8 2, i8 2>
+ %shuffle = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 0, i32 1>
+ %retval = select <2 x i1> %cmp, <2 x i8> %shuffle, <2 x i8> %x
+ ret <2 x i8> %retval
+}
+
+define <4 x i8> @select_icmp_shufflevector_select(<4 x i8> %x, <4 x i8> %y, <4 x i8> %z) {
+; CHECK-LABEL: define <4 x i8> @select_icmp_shufflevector_select(
+; CHECK-SAME: <4 x i8> [[X:%.*]], <4 x i8> [[Y:%.*]], <4 x i8> [[Z:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <4 x i8> [[Y]], <i8 2, i8 2, i8 2, i8 2>
+; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x i8> [[Z]], <4 x i8> [[Y]], <4 x i32> <i32 0, i32 5, i32 2, i32 7>
+; CHECK-NEXT: [[RETVAL:%.*]] = select <4 x i1> [[CMP]], <4 x i8> [[SHUFFLE]], <4 x i8> [[X]]
+; CHECK-NEXT: ret <4 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <4 x i8> %y, <i8 2, i8 2, i8 2, i8 2>
+ %shuffle = shufflevector <4 x i8> %y, <4 x i8> %z, <4 x i32> <i32 4, i32 1, i32 6, i32 3>
+ %retval = select <4 x i1> %cmp, <4 x i8> %shuffle, <4 x i8> %x
+ ret <4 x i8> %retval
+}
+
+define <2 x i8> @select_icmp_shufflevector_lanecrossing(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_shufflevector_lanecrossing(
+; CHECK-SAME: <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i8> [[Y]], <i8 2, i8 2>
+; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <2 x i8> [[Y]], <2 x i8> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[SHUFFLE]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <2 x i8> %y, <i8 2, i8 2>
+ %shuffle = shufflevector <2 x i8> %y, <2 x i8> poison, <2 x i32> <i32 1, i32 0>
+ %retval = select <2 x i1> %cmp, <2 x i8> %shuffle, <2 x i8> %x
+ ret <2 x i8> %retval
+}
+
+declare <2 x i8> @fn(<2 x i8>)
----------------
nikic wrote:
```suggestion
declare <2 x i8> @fn(<2 x i8>) speculatable
```
Otherwise it will already be rejected because of that.
https://github.com/llvm/llvm-project/pull/111694
More information about the llvm-commits
mailing list