[llvm] InstCombine/test: cover foldSelectValueEquivalence (PR #111694)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 01:59:21 PDT 2024
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/111694
>From 1b08becaed830cf640412a34baf24bfb43a2bfdc Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <ramkumar.ramachandra at codasip.com>
Date: Wed, 9 Oct 2024 16:05:16 +0100
Subject: [PATCH] InstCombine/test: cover foldSelectValueEquivalence
Write dedicated tests for foldSelectValueEquivalence, demonstrating that
it does not perform many GVN-like replacements when:
- the comparison is a vector-type
- the comparison is a floating-point type
- the instruction is not speculable in general
as a prelude to fixing these deficiencies.
---
.../InstCombine/select-value-equivalence.ll | 267 ++++++++++++++++++
1 file changed, 267 insertions(+)
create mode 100644 llvm/test/Transforms/InstCombine/select-value-equivalence.ll
diff --git a/llvm/test/Transforms/InstCombine/select-value-equivalence.ll b/llvm/test/Transforms/InstCombine/select-value-equivalence.ll
new file mode 100644
index 00000000000000..c7630834d2202e
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/select-value-equivalence.ll
@@ -0,0 +1,267 @@
+; 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
+}
+
+define i8 @select_icmp_udiv(i8 %x, i8 %y) {
+; CHECK-LABEL: define i8 @select_icmp_udiv(
+; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y]], 2
+; CHECK-NEXT: [[UDIV:%.*]] = udiv i8 [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP]], i8 [[UDIV]], i8 [[X]]
+; CHECK-NEXT: ret i8 [[RETVAL]]
+;
+ %cmp = icmp eq i8 %y, 2
+ %udiv = udiv i8 %x, %y
+ %retval = select i1 %cmp, i8 %udiv, i8 %x
+ ret i8 %retval
+}
+
+define i8 @select_icmp_urem(i8 %x, i8 %y) {
+; CHECK-LABEL: define i8 @select_icmp_urem(
+; CHECK-SAME: i8 [[X:%.*]], i8 [[Y:%.*]]) {
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[Y]], 2
+; CHECK-NEXT: [[UREM:%.*]] = urem i8 [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select i1 [[CMP]], i8 [[UREM]], i8 [[X]]
+; CHECK-NEXT: ret i8 [[RETVAL]]
+;
+ %cmp = icmp eq i8 %y, 2
+ %urem = urem i8 %x, %y
+ %retval = select i1 %cmp, i8 %urem, i8 %x
+ ret i8 %retval
+}
+
+define <2 x i8> @select_icmp_udiv_vec(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_udiv_vec(
+; 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: [[UDIV:%.*]] = udiv <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[UDIV]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <2 x i8> %y, <i8 2, i8 2>
+ %udiv = udiv <2 x i8> %x, %y
+ %retval = select <2 x i1> %cmp, <2 x i8> %udiv, <2 x i8> %x
+ ret <2 x i8> %retval
+}
+
+define <2 x i8> @select_icmp_urem_vec(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_urem_vec(
+; 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: [[UREM:%.*]] = urem <2 x i8> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[UREM]], <2 x i8> [[X]]
+; CHECK-NEXT: ret <2 x i8> [[RETVAL]]
+;
+ %cmp = icmp eq <2 x i8> %y, <i8 2, i8 2>
+ %urem = urem <2 x i8> %x, %y
+ %retval = select <2 x i1> %cmp, <2 x i8> %urem, <2 x i8> %x
+ ret <2 x i8> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_oeq_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_oeq_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[FADD]], <2 x double> [[X]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp oeq <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %fadd, <2 x double> %x
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_une_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_une_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp une <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[X]], <2 x double> [[FADD]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp une <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %x, <2 x double> %fadd
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_ueq_nnan_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_ueq_nnan_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp nnan ueq <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[FADD]], <2 x double> [[X]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp nnan ueq <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %fadd, <2 x double> %x
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_one_nnan_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_one_nnan_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp nnan one <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[X]], <2 x double> [[FADD]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp nnan one <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %x, <2 x double> %fadd
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_ueq_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_ueq_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp ueq <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[FADD]], <2 x double> [[X]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp ueq <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %fadd, <2 x double> %x
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_one_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_one_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp one <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[X]], <2 x double> [[FADD]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp one <2 x double> %y, <double 2.0, double 2.0>
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %x, <2 x double> %fadd
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_oeq_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_oeq_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq <2 x double> [[Y]], zeroinitializer
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[FADD]], <2 x double> [[X]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp oeq <2 x double> %y, zeroinitializer
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %fadd, <2 x double> %x
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fadd_une_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fadd_une_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp une <2 x double> [[Y]], zeroinitializer
+; CHECK-NEXT: [[FADD:%.*]] = fadd <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[X]], <2 x double> [[FADD]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp une <2 x double> %y, zeroinitializer
+ %fadd = fadd <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %x, <2 x double> %fadd
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fdiv_oeq_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_oeq_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp oeq <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[DIV:%.*]] = fdiv <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[DIV]], <2 x double> [[X]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp oeq <2 x double> %y, <double 2.0, double 2.0>
+ %div = fdiv <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %div, <2 x double> %x
+ ret <2 x double> %retval
+}
+
+define <2 x double> @select_fcmp_fdiv_une_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_une_not_zero_vec(
+; CHECK-SAME: <2 x double> [[X:%.*]], <2 x double> [[Y:%.*]]) {
+; CHECK-NEXT: [[FCMP:%.*]] = fcmp une <2 x double> [[Y]], <double 2.000000e+00, double 2.000000e+00>
+; CHECK-NEXT: [[DIV:%.*]] = fdiv <2 x double> [[X]], [[Y]]
+; CHECK-NEXT: [[RETVAL:%.*]] = select <2 x i1> [[FCMP]], <2 x double> [[X]], <2 x double> [[DIV]]
+; CHECK-NEXT: ret <2 x double> [[RETVAL]]
+;
+ %fcmp = fcmp une <2 x double> %y, <double 2.0, double 2.0>
+ %div = fdiv <2 x double> %x, %y
+ %retval = select <2 x i1> %fcmp, <2 x double> %x, <2 x double> %div
+ ret <2 x double> %retval
+}
More information about the llvm-commits
mailing list