Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstCombine/test: cover foldSelectValueEquivalence #111694

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

artagnon
Copy link
Contributor

@artagnon artagnon commented Oct 9, 2024

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

as a prelude to fixing these deficiencies.

@llvmbot
Copy link
Member

llvmbot commented Oct 9, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Ramkumar Ramachandra (artagnon)

Changes

Write dedicated tests for foldSelectValueEquivalence, demonstrating that it does not perform many GVN-like replacements on vector-values, as a prelude to fixing this deficiency.


Full diff: https://github.com/llvm/llvm-project/pull/111694.diff

1 Files Affected:

  • (added) llvm/test/Transforms/InstCombine/select-value-equivalence.ll (+183)
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..c8224e3b607404
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/select-value-equivalence.ll
@@ -0,0 +1,183 @@
+; 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) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_insertelement_eq(
+; 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 0>, <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 1
+  %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) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_insertelement_ne(
+; CHECK-SAME: <2 x i8> [[X:%.*]], <2 x i8> [[Y:%.*]]) {
+; CHECK-NEXT:    [[CMP_NOT:%.*]] = icmp eq <2 x i8> [[Y]], <i8 2, i8 2>
+; CHECK-NEXT:    [[RETVAL:%.*]] = select <2 x i1> [[CMP_NOT]], <2 x i8> <i8 2, i8 0>, <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 1
+  %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(<2 x i8> %x, <2 x i8> %y) {
+; CHECK-LABEL: define <2 x i8> @select_icmp_shufflevector(
+; 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 <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_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
+}
+
+define <2 x double> @select_fcmp_fdiv_ueq_nnan_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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 nnan ueq <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_one_nnan_not_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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 nnan one <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
+}
+
+define <2 x double> @select_fcmp_fdiv_ueq_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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 ueq <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_one_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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 one <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
+}
+
+define <2 x double> @select_fcmp_fdiv_oeq_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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, zeroinitializer
+  %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_zero_vec(<2 x double> %x, <2 x double> %y) {
+; CHECK-LABEL: define <2 x double> @select_fcmp_fdiv_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:    [[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, zeroinitializer
+  %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
+}
+

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

as a prelude to fixing these deficiencies.
@artagnon artagnon force-pushed the ic-select-equiv-test branch from 0fde07a to b52b98d Compare October 14, 2024 14:35
Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@artagnon artagnon merged commit fe526ae into llvm:main Oct 15, 2024
5 of 6 checks passed
@artagnon artagnon deleted the ic-select-equiv-test branch October 15, 2024 09:33
DanielCChen pushed a commit to DanielCChen/llvm-project that referenced this pull request Oct 16, 2024
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

 as a prelude to fixing these deficiencies.
bricknerb pushed a commit to bricknerb/llvm-project that referenced this pull request Oct 17, 2024
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

 as a prelude to fixing these deficiencies.
EricWF pushed a commit to efcs/llvm-project that referenced this pull request Oct 22, 2024
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

 as a prelude to fixing these deficiencies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants