diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2018-03-14 17:31:03 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2018-03-14 17:31:03 +0000 |
commit | 6ab60358ca6395da47d85c8368798e7c93f2c3ba (patch) | |
tree | 0dc7a397ddd568e769c2c2fd1c5eb4ad7d76e715 | |
parent | 084e7d8770a27a7caf80a6eb63fbe07d61c6b198 (diff) | |
download | bcm5719-llvm-6ab60358ca6395da47d85c8368798e7c93f2c3ba.tar.gz bcm5719-llvm-6ab60358ca6395da47d85c8368798e7c93f2c3ba.zip |
[InstCombine] [NFC] Add tests for peeking through unsigned FP casts for zero-equality compares (PR36682)
Summary:
This pattern came up in PR36682 / D44390
https://bugs.llvm.org/show_bug.cgi?id=36682
https://reviews.llvm.org/D44390
https://godbolt.org/g/oKvT5H
Looking at the IR pattern in question, as per [[ https://github.com/rutgers-apl/alive-nj | alive-nj ]], for all the type combinations i checked
(input: `i16`, `i32`, `i64`; intermediate: `half`/`i16`, `float`/`i32`, `double`/`i64`)
for the following `icmp` comparisons the `uitofp`+`bitcast` can be dropped:
* `eq 0`
* `ne 0`
I did not check vectors, but i'm guessing it's the same there.
{F5889189}
Thus all these cases are in the testcase (along with the vector variant with additional `undef` element in the middle).
There are no negative patterns here (unless alive-nj lied/is broken), all of these should be optimized.
Generated with
{F5889196}
Reviewers: spatel, majnemer, efriedma, arsenm
Reviewed By: spatel
Subscribers: wdng, llvm-commits
Differential Revision: https://reviews.llvm.org/D44416
llvm-svn: 327534
-rw-r--r-- | llvm/test/Transforms/InstCombine/cast-unsigned-icmp-eqcmp-0.ll | 243 |
1 files changed, 243 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/cast-unsigned-icmp-eqcmp-0.ll b/llvm/test/Transforms/InstCombine/cast-unsigned-icmp-eqcmp-0.ll new file mode 100644 index 00000000000..f54388377bc --- /dev/null +++ b/llvm/test/Transforms/InstCombine/cast-unsigned-icmp-eqcmp-0.ll @@ -0,0 +1,243 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -instcombine -S | FileCheck %s + +; target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +; This is related to https://bugs.llvm.org/show_bug.cgi?id=36682 + +; FIXME: *all* of these are true tests. +; In *all* of these, uitofp and bitcast should be instcombine'd out. + +define i1 @i32_cast_cmp_eq_int_0_uitofp_float(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float +; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to float + %b = bitcast float %f to i32 + %cmp = icmp eq i32 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i32> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x float> + %b = bitcast <2 x float> %f to <2 x i32> + %cmp = icmp eq <2 x i32> %b, <i32 0, i32 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_float_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_float_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x float> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x float> [[F]] to <3 x i32> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <3 x i32> [[B]], <i32 0, i32 undef, i32 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x float> + %b = bitcast <3 x float> %f to <3 x i32> + %cmp = icmp eq <3 x i32> %b, <i32 0, i32 undef, i32 0> + ret <3 x i1> %cmp +} + +define i1 @i32_cast_cmp_ne_int_0_uitofp_float(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to float +; CHECK-NEXT: [[B:%.*]] = bitcast float [[F]] to i32 +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to float + %b = bitcast float %f to i32 + %cmp = icmp ne i32 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x float> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x float> [[F]] to <2 x i32> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i32> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x float> + %b = bitcast <2 x float> %f to <2 x i32> + %cmp = icmp ne <2 x i32> %b, <i32 0, i32 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_float_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_float_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x float> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x float> [[F]] to <3 x i32> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <3 x i32> [[B]], <i32 0, i32 undef, i32 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x float> + %b = bitcast <3 x float> %f to <3 x i32> + %cmp = icmp ne <3 x i32> %b, <i32 0, i32 undef, i32 0> + ret <3 x i1> %cmp +} + +define i1 @i32_cast_cmp_eq_int_0_uitofp_double(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double +; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to double + %b = bitcast double %f to i64 + %cmp = icmp eq i64 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i64> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x double> + %b = bitcast <2 x double> %f to <2 x i64> + %cmp = icmp eq <2 x i64> %b, <i64 0, i64 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_double_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_double_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x double> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x double> [[F]] to <3 x i64> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <3 x i64> [[B]], <i64 0, i64 undef, i64 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x double> + %b = bitcast <3 x double> %f to <3 x i64> + %cmp = icmp eq <3 x i64> %b, <i64 0, i64 undef, i64 0> + ret <3 x i1> %cmp +} + +define i1 @i32_cast_cmp_ne_int_0_uitofp_double(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to double +; CHECK-NEXT: [[B:%.*]] = bitcast double [[F]] to i64 +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i64 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to double + %b = bitcast double %f to i64 + %cmp = icmp ne i64 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x double> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x double> [[F]] to <2 x i64> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i64> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x double> + %b = bitcast <2 x double> %f to <2 x i64> + %cmp = icmp ne <2 x i64> %b, <i64 0, i64 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_double_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_double_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x double> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x double> [[F]] to <3 x i64> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <3 x i64> [[B]], <i64 0, i64 undef, i64 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x double> + %b = bitcast <3 x double> %f to <3 x i64> + %cmp = icmp ne <3 x i64> %b, <i64 0, i64 undef, i64 0> + ret <3 x i1> %cmp +} + +define i1 @i32_cast_cmp_eq_int_0_uitofp_half(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half +; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i16 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to half + %b = bitcast half %f to i16 + %cmp = icmp eq i16 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i16> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x half> + %b = bitcast <2 x half> %f to <2 x i16> + %cmp = icmp eq <2 x i16> %b, <i16 0, i16 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_eq_int_0_uitofp_half_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_eq_int_0_uitofp_half_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x half> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x half> [[F]] to <3 x i16> +; CHECK-NEXT: [[CMP:%.*]] = icmp eq <3 x i16> [[B]], <i16 0, i16 undef, i16 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x half> + %b = bitcast <3 x half> %f to <3 x i16> + %cmp = icmp eq <3 x i16> %b, <i16 0, i16 undef, i16 0> + ret <3 x i1> %cmp +} + +define i1 @i32_cast_cmp_ne_int_0_uitofp_half(i32 %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half( +; CHECK-NEXT: [[F:%.*]] = uitofp i32 [[I:%.*]] to half +; CHECK-NEXT: [[B:%.*]] = bitcast half [[F]] to i16 +; CHECK-NEXT: [[CMP:%.*]] = icmp ne i16 [[B]], 0 +; CHECK-NEXT: ret i1 [[CMP]] +; + %f = uitofp i32 %i to half + %b = bitcast half %f to i16 + %cmp = icmp ne i16 %b, 0 + ret i1 %cmp +} + +define <2 x i1> @i32_cast_cmp_ne_int_0_uitofp_half_vec(<2 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half_vec( +; CHECK-NEXT: [[F:%.*]] = uitofp <2 x i32> [[I:%.*]] to <2 x half> +; CHECK-NEXT: [[B:%.*]] = bitcast <2 x half> [[F]] to <2 x i16> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i16> [[B]], zeroinitializer +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %f = uitofp <2 x i32> %i to <2 x half> + %b = bitcast <2 x half> %f to <2 x i16> + %cmp = icmp ne <2 x i16> %b, <i16 0, i16 0> + ret <2 x i1> %cmp +} + +define <3 x i1> @i32_cast_cmp_ne_int_0_uitofp_half_vec_undef(<3 x i32> %i) { +; CHECK-LABEL: @i32_cast_cmp_ne_int_0_uitofp_half_vec_undef( +; CHECK-NEXT: [[F:%.*]] = uitofp <3 x i32> [[I:%.*]] to <3 x half> +; CHECK-NEXT: [[B:%.*]] = bitcast <3 x half> [[F]] to <3 x i16> +; CHECK-NEXT: [[CMP:%.*]] = icmp ne <3 x i16> [[B]], <i16 0, i16 undef, i16 0> +; CHECK-NEXT: ret <3 x i1> [[CMP]] +; + %f = uitofp <3 x i32> %i to <3 x half> + %b = bitcast <3 x half> %f to <3 x i16> + %cmp = icmp ne <3 x i16> %b, <i16 0, i16 undef, i16 0> + ret <3 x i1> %cmp +} |