blob: ee8be3ca1bf89f09db77fe77b3b22e462bfbf30b [file]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
; RUN: opt -S -passes=instcombine < %s | FileCheck %s
declare nofpclass(inf zero sub norm) <4 x half> @returns_nan()
declare nofpclass(nan zero sub norm) <4 x half> @returns_inf()
declare nofpclass(inf zero sub norm) half @returns_nan_f16()
define nofpclass(inf zero sub norm) <4 x half> @ret_only_nan__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(inf zero sub norm) <4 x half> @ret_only_nan__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[VEC0]], <4 x half> [[VEC1]], <4 x i32> <i32 6, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(qnan inf zero sub norm) <4 x half> @ret_only_snan__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(qnan inf zero sub norm) <4 x half> @ret_only_snan__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[VEC0]], <4 x half> [[VEC1]], <4 x i32> <i32 6, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(snan inf zero sub norm) <4 x half> @ret_only_qnan__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(snan inf zero sub norm) <4 x half> @ret_only_qnan__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[VEC0]], <4 x half> [[VEC1]], <4 x i32> <i32 6, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan inf sub norm) <4 x half> @ret_only_zero__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan inf sub norm) <4 x half> @ret_only_zero__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[VEC0]], <4 x half> [[VEC1]], <4 x i32> <i32 6, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan inf nzero sub norm) <4 x half> @ret_only_pzero__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) <4 x half> @ret_only_pzero__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: ret <4 x half> zeroinitializer
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan inf pzero sub norm) <4 x half> @ret_only_nzero__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan inf pzero sub norm) <4 x half> @ret_only_nzero__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: ret <4 x half> splat (half 0xH8000)
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan zero sub norm) <4 x half> @ret_only_inf__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan zero sub norm) <4 x half> @ret_only_inf__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[VEC0]], <4 x half> [[VEC1]], <4 x i32> <i32 6, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan ninf zero sub norm) <4 x half> @ret_only_pinf__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan ninf zero sub norm) <4 x half> @ret_only_pinf__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: ret <4 x half> splat (half 0xH7C00)
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan pinf zero sub norm) <4 x half> @ret_only_ninf__shufflevector_unknown(<4 x half> %vec0, <4 x half> %vec1) {
; CHECK-LABEL: define nofpclass(nan pinf zero sub norm) <4 x half> @ret_only_ninf__shufflevector_unknown(
; CHECK-SAME: <4 x half> [[VEC0:%.*]], <4 x half> [[VEC1:%.*]]) {
; CHECK-NEXT: ret <4 x half> splat (half 0xHFC00)
;
%shuffle = shufflevector <4 x half> %vec0, <4 x half> %vec1, <4 x i32> <i32 6, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_one_input_select_nan(i1 %cond, <4 x half> %unknown) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_one_input_select_nan(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[UNKNOWN]], <4 x half> poison, <4 x i32> <i32 3, i32 1, i32 0, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%nan = call <4 x half> @returns_nan()
%select = select i1 %cond, <4 x half> %nan, <4 x half> %unknown
%shuffle = shufflevector <4 x half> %select, <4 x half> poison, <4 x i32> <i32 3, i32 1, i32 0, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_select_nans(i1 %cond, <4 x half> %unknown0, <4 x half> %unknown1) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_select_nans(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> [[UNKNOWN0:%.*]], <4 x half> [[UNKNOWN1:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[UNKNOWN0]], <4 x half> [[UNKNOWN1]], <4 x i32> <i32 4, i32 7, i32 1, i32 3>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%nan = call <4 x half> @returns_nan()
%select0 = select i1 %cond, <4 x half> %nan, <4 x half> %unknown0
%select1 = select i1 %cond, <4 x half> %unknown1, <4 x half> %nan
%shuffle = shufflevector <4 x half> %select0, <4 x half> %select1, <4 x i32> <i32 4, i32 7, i32 1, i32 3>
ret <4 x half> %shuffle
}
define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_eliminate_vector0(<4 x half> %unknown) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_eliminate_vector0(
; CHECK-SAME: <4 x half> [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[UNKNOWN]], <4 x half> poison, <4 x i32> <i32 0, i32 3, i32 poison, i32 poison>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%nan = call <4 x half> @returns_nan()
%shuffle = shufflevector <4 x half> %nan, <4 x half> %unknown, <4 x i32> <i32 4, i32 7, i32 1, i32 3>
ret <4 x half> %shuffle
}
define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_eliminate_vector1(<4 x half> %unknown) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_no_nan__shufflevector_two_input_eliminate_vector1(
; CHECK-SAME: <4 x half> [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[UNKNOWN]], <4 x half> poison, <4 x i32> <i32 poison, i32 poison, i32 1, i32 3>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%nan = call <4 x half> @returns_nan()
%shuffle = shufflevector <4 x half> %unknown, <4 x half> %nan, <4 x i32> <i32 4, i32 7, i32 1, i32 3>
ret <4 x half> %shuffle
}
; Cannot simplify
define nofpclass(inf nan) <4 x half> @ret_nonan_noinf___shuffle_not_nan_not_inf(i1 %cond, <4 x half> nofpclass(nan) %not.nan, <4 x half> %not.inf) {
; CHECK-LABEL: define nofpclass(nan inf) <4 x half> @ret_nonan_noinf___shuffle_not_nan_not_inf(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> nofpclass(nan) [[NOT_NAN:%.*]], <4 x half> [[NOT_INF:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[NOT_NAN]], <4 x half> [[NOT_INF]], <4 x i32> <i32 4, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%shuffle = shufflevector <4 x half> %not.nan, <4 x half> %not.inf, <4 x i32> <i32 4, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
; poison
define nofpclass(inf nan) <4 x half> @ret_nonan_noinf__shufflevector_nan_inf(i1 %cond) {
; CHECK-LABEL: define nofpclass(nan inf) <4 x half> @ret_nonan_noinf__shufflevector_nan_inf(
; CHECK-SAME: i1 [[COND:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[INF:%.*]] = call <4 x half> @returns_inf()
; CHECK-NEXT: ret <4 x half> <half undef, half poison, half poison, half poison>
;
%nan = call <4 x half> @returns_nan()
%inf = call <4 x half> @returns_inf()
%shuffle = shufflevector <4 x half> %inf, <4 x half> %nan, <4 x i32> <i32 4, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(ninf nnorm nsub nzero) <4 x half> @ret_positives___shuffle_fabs_positive_or_nans(i1 %cond, <4 x half> nofpclass(ninf nnorm nsub nzero) %known.positive0, <4 x half> nofpclass(ninf nnorm nsub nzero) %known.positive1) {
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) <4 x half> @ret_positives___shuffle_fabs_positive_or_nans(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> nofpclass(ninf nzero nsub nnorm) [[KNOWN_POSITIVE0:%.*]], <4 x half> nofpclass(ninf nzero nsub nnorm) [[KNOWN_POSITIVE1:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x half> [[KNOWN_POSITIVE0]], <4 x half> [[KNOWN_POSITIVE1]], <4 x i32> <i32 4, i32 2, i32 3, i32 0>
; CHECK-NEXT: [[SHUFFLE:%.*]] = call <4 x half> @llvm.fabs.v4f16(<4 x half> [[TMP1]])
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%fabs.0 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive0)
%fabs.1 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive1)
%shuffle = shufflevector <4 x half> %fabs.0, <4 x half> %fabs.1, <4 x i32> <i32 4, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(ninf nnorm nsub nzero) <4 x half> @ret_positives___shuffle_fabs_positives(i1 %cond, <4 x half> nofpclass(nan ninf nnorm nsub nzero) %known.positive0, <4 x half> nofpclass(nan ninf nnorm nsub nzero) %known.positive1) {
; CHECK-LABEL: define nofpclass(ninf nzero nsub nnorm) <4 x half> @ret_positives___shuffle_fabs_positives(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> nofpclass(nan ninf nzero nsub nnorm) [[KNOWN_POSITIVE0:%.*]], <4 x half> nofpclass(nan ninf nzero nsub nnorm) [[KNOWN_POSITIVE1:%.*]]) {
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[KNOWN_POSITIVE0]], <4 x half> [[KNOWN_POSITIVE1]], <4 x i32> <i32 4, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[SHUFFLE]]
;
%fabs.0 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive0)
%fabs.1 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive1)
%shuffle = shufflevector <4 x half> %fabs.0, <4 x half> %fabs.1, <4 x i32> <i32 4, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
; TODO: Should be able to eliminate fabs with no-nans from return
define nofpclass(nan ninf nnorm nsub nzero) <4 x half> @ret_positives_non_nan___shuffle_fabs(i1 %cond, <4 x half> nofpclass(ninf nnorm nsub nzero) %known.positive0, <4 x half> nofpclass(ninf nnorm nsub nzero) %known.positive1) {
; CHECK-LABEL: define nofpclass(nan ninf nzero nsub nnorm) <4 x half> @ret_positives_non_nan___shuffle_fabs(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> nofpclass(ninf nzero nsub nnorm) [[KNOWN_POSITIVE0:%.*]], <4 x half> nofpclass(ninf nzero nsub nnorm) [[KNOWN_POSITIVE1:%.*]]) {
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x half> [[KNOWN_POSITIVE0]], <4 x half> [[KNOWN_POSITIVE1]], <4 x i32> <i32 4, i32 2, i32 3, i32 0>
; CHECK-NEXT: ret <4 x half> [[TMP1]]
;
%fabs.0 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive0)
%fabs.1 = call <4 x half> @llvm.fabs.v4f16(<4 x half> %known.positive1)
%shuffle = shufflevector <4 x half> %fabs.0, <4 x half> %fabs.1, <4 x i32> <i32 4, i32 2, i32 3, i32 0>
ret <4 x half> %shuffle
}
define nofpclass(nan) <4 x half> @ret_nonan_splat(i1 %cond, half %unknown) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_nonan_splat(
; CHECK-SAME: i1 [[COND:%.*]], half [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call half @returns_nan_f16()
; CHECK-NEXT: [[UNKNOWN_VEC:%.*]] = insertelement <4 x half> poison, half [[UNKNOWN]], i64 0
; CHECK-NEXT: [[SPLAT_UNKNOWN:%.*]] = shufflevector <4 x half> [[UNKNOWN_VEC]], <4 x half> poison, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x half> [[SPLAT_UNKNOWN]]
;
%nan = call half @returns_nan_f16()
%nan.vec = insertelement <4 x half> poison, half %nan, i32 0
%unknown.vec = insertelement <4 x half> poison, half %unknown, i32 0
%splat.nan = shufflevector <4 x half> %nan.vec, <4 x half> poison, <4 x i32> zeroinitializer
%splat.unknown = shufflevector <4 x half> %unknown.vec, <4 x half> poison, <4 x i32> zeroinitializer
%select = select i1 %cond, <4 x half> %splat.nan, <4 x half> %splat.unknown
ret <4 x half> %select
}
define nofpclass(nan) <4 x half> @ret_nonan_splat_select_unknown_or_nan(i1 %cond, half %unknown) {
; CHECK-LABEL: define nofpclass(nan) <4 x half> @ret_nonan_splat_select_unknown_or_nan(
; CHECK-SAME: i1 [[COND:%.*]], half [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call half @returns_nan_f16()
; CHECK-NEXT: [[SELECT_VEC:%.*]] = insertelement <4 x half> poison, half [[UNKNOWN]], i64 0
; CHECK-NEXT: [[SPLAT:%.*]] = shufflevector <4 x half> [[SELECT_VEC]], <4 x half> poison, <4 x i32> zeroinitializer
; CHECK-NEXT: ret <4 x half> [[SPLAT]]
;
%nan = call half @returns_nan_f16()
%select = select i1 %cond, half %nan, half %unknown
%select.vec = insertelement <4 x half> poison, half %select, i32 0
%splat = shufflevector <4 x half> %select.vec, <4 x half> poison, <4 x i32> zeroinitializer
ret <4 x half> %splat
}
; Do not rewrite exp into fadd
define nofpclass(snan) <4 x half> @ret_nonnan_rhs_taints_known_nan_result(i1 %cond, <4 x half> %unknown) {
; CHECK-LABEL: define nofpclass(snan) <4 x half> @ret_nonnan_rhs_taints_known_nan_result(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[NAN]], <4 x half> [[UNKNOWN]], <4 x i32> <i32 5, i32 0, i32 1, i32 3>
; CHECK-NEXT: [[EXP:%.*]] = call <4 x half> @llvm.exp.v4f16(<4 x half> [[SHUFFLE]])
; CHECK-NEXT: ret <4 x half> [[EXP]]
;
%nan = call <4 x half> @returns_nan()
%shuffle = shufflevector <4 x half> %nan, <4 x half> %unknown, <4 x i32> <i32 5, i32 0, i32 1, i32 3>
%exp = call <4 x half> @llvm.exp.v4f16(<4 x half> %shuffle)
ret <4 x half> %exp
}
; Do not rewrite exp into fadd
define nofpclass(snan) <4 x half> @ret_nonnan_lhs_taints_known_nan_result(i1 %cond, <4 x half> %unknown) {
; CHECK-LABEL: define nofpclass(snan) <4 x half> @ret_nonnan_lhs_taints_known_nan_result(
; CHECK-SAME: i1 [[COND:%.*]], <4 x half> [[UNKNOWN:%.*]]) {
; CHECK-NEXT: [[NAN:%.*]] = call <4 x half> @returns_nan()
; CHECK-NEXT: [[SHUFFLE:%.*]] = shufflevector <4 x half> [[UNKNOWN]], <4 x half> [[NAN]], <4 x i32> <i32 5, i32 0, i32 1, i32 3>
; CHECK-NEXT: [[EXP:%.*]] = call <4 x half> @llvm.exp.v4f16(<4 x half> [[SHUFFLE]])
; CHECK-NEXT: ret <4 x half> [[EXP]]
;
%nan = call <4 x half> @returns_nan()
%shuffle = shufflevector <4 x half> %unknown, <4 x half> %nan, <4 x i32> <i32 5, i32 0, i32 1, i32 3>
%exp = call <4 x half> @llvm.exp.v4f16(<4 x half> %shuffle)
ret <4 x half> %exp
}