; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+declare <2 x half> @llvm.fabs.v2f16(<2 x half>)
+declare <2 x float> @llvm.fabs.v2f32(<2 x float>)
+declare <4 x float> @llvm.fabs.v4f32(<4 x float>)
+declare <2 x double> @llvm.fabs.v2f64(<2 x double>)
+declare <4 x double> @llvm.fabs.v4f64(<4 x double>)
+
define <4 x float> @test1(<4 x float> %v1) {
; CHECK-LABEL: @test1(
; CHECK-NEXT: ret <4 x float> [[V1:%.*]]
; CHECK-LABEL: @test13a(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i8> undef, i8 [[X2:%.*]], i64 0
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i8> [[TMP1]], i8 [[X1:%.*]], i64 1
-; CHECK-NEXT: [[TMP3:%.*]] = add <2 x i8> [[TMP2]], <i8 7, i8 5>
-; CHECK-NEXT: ret <2 x i8> [[TMP3]]
+; CHECK-NEXT: [[D:%.*]] = add <2 x i8> [[TMP2]], <i8 7, i8 5>
+; CHECK-NEXT: ret <2 x i8> [[D]]
;
%A = insertelement <2 x i8> undef, i8 %x1, i32 0
%B = insertelement <2 x i8> %A, i8 %x2, i32 1
define <3 x i8> @fold_inselts_with_widening_shuffle(i8 %x, i8 %y) {
; CHECK-LABEL: @fold_inselts_with_widening_shuffle(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <3 x i8> undef, i8 [[X:%.*]], i64 0
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <3 x i8> [[TMP1]], i8 [[Y:%.*]], i64 1
-; CHECK-NEXT: ret <3 x i8> [[TMP2]]
+; CHECK-NEXT: [[WIDEN:%.*]] = insertelement <3 x i8> [[TMP1]], i8 [[Y:%.*]], i64 1
+; CHECK-NEXT: ret <3 x i8> [[WIDEN]]
;
%ins0 = insertelement <2 x i8> undef, i8 %x, i32 0
%ins1 = insertelement <2 x i8> %ins0, i8 %y, i32 1
define <2 x i8> @test13c(i8 %x1, i8 %x2) {
; CHECK-LABEL: @test13c(
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i8> undef, i8 [[X1:%.*]], i64 0
-; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i8> [[TMP1]], i8 [[X2:%.*]], i64 1
-; CHECK-NEXT: ret <2 x i8> [[TMP2]]
+; CHECK-NEXT: [[C:%.*]] = insertelement <2 x i8> [[TMP1]], i8 [[X2:%.*]], i64 1
+; CHECK-NEXT: ret <2 x i8> [[C]]
;
%A = insertelement <4 x i8> undef, i8 %x1, i32 0
%B = insertelement <4 x i8> %A, i8 %x2, i32 2
ret <4 x i32> %a
}
+define <2 x float> @fabs_unary_shuf(<2 x float> %x) {
+; CHECK-LABEL: @fabs_unary_shuf(
+; CHECK-NEXT: [[NX:%.*]] = call nnan nsz <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[NX]], <2 x float> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %nx = call nsz nnan <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
+ %r = shufflevector <2 x float> %nx, <2 x float> poison, <2 x i32> <i32 1, i32 0>
+ ret <2 x float> %r
+}
+
+define <4 x half> @fabs_unary_shuf_widen(<2 x half> %x) {
+; CHECK-LABEL: @fabs_unary_shuf_widen(
+; CHECK-NEXT: [[NX:%.*]] = call ninf <2 x half> @llvm.fabs.v2f16(<2 x half> [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x half> [[NX]], <2 x half> poison, <4 x i32> <i32 1, i32 0, i32 0, i32 undef>
+; CHECK-NEXT: ret <4 x half> [[R]]
+;
+ %nx = call ninf <2 x half> @llvm.fabs.v2f16(<2 x half> %x)
+ %r = shufflevector <2 x half> %nx, <2 x half> poison, <4 x i32> <i32 1, i32 0, i32 0, i32 poison>
+ ret <4 x half> %r
+}
+
+define <2 x double> @fabs_unary_shuf_narrow(<4 x double> %x) {
+; CHECK-LABEL: @fabs_unary_shuf_narrow(
+; CHECK-NEXT: [[NX:%.*]] = call nsz <4 x double> @llvm.fabs.v4f64(<4 x double> [[X:%.*]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x double> [[NX]], <4 x double> poison, <2 x i32> <i32 3, i32 0>
+; CHECK-NEXT: ret <2 x double> [[R]]
+;
+ %nx = call nsz <4 x double> @llvm.fabs.v4f64(<4 x double> %x)
+ %r = shufflevector <4 x double> %nx, <4 x double> poison, <2 x i32> <i32 3, i32 0>
+ ret <2 x double> %r
+}
+
+define <2 x float> @fabs_unary_shuf_use(<2 x float> %x) {
+; CHECK-LABEL: @fabs_unary_shuf_use(
+; CHECK-NEXT: [[NX:%.*]] = call nsz <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: call void @use(<2 x float> [[NX]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[NX]], <2 x float> poison, <2 x i32> <i32 undef, i32 0>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %nx = call nsz <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
+ call void @use(<2 x float> %nx)
+ %r = shufflevector <2 x float> %nx, <2 x float> poison, <2 x i32> <i32 3, i32 0>
+ ret <2 x float> %r
+}
+
+define <4 x float> @fabs_shuf(<4 x float> %x, <4 x float> %y) {
+; CHECK-LABEL: @fabs_shuf(
+; CHECK-NEXT: [[NX:%.*]] = call ninf nsz <4 x float> @llvm.fabs.v4f32(<4 x float> [[X:%.*]])
+; CHECK-NEXT: [[NY:%.*]] = call nnan ninf <4 x float> @llvm.fabs.v4f32(<4 x float> [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[NX]], <4 x float> [[NY]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+; CHECK-NEXT: ret <4 x float> [[R]]
+;
+ %nx = call nsz ninf <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+ %ny = call nnan ninf <4 x float> @llvm.fabs.v4f32(<4 x float> %y)
+ %r = shufflevector <4 x float> %nx, <4 x float> %ny, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+ ret <4 x float> %r
+}
+
+define <4 x float> @fabs_shuf_widen_use1(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fabs_shuf_widen_use1(
+; CHECK-NEXT: [[NX:%.*]] = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: call void @use(<2 x float> [[NX]])
+; CHECK-NEXT: [[NY:%.*]] = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[NX]], <2 x float> [[NY]], <4 x i32> <i32 undef, i32 1, i32 2, i32 3>
+; CHECK-NEXT: ret <4 x float> [[R]]
+;
+ %nx = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
+ call void @use(<2 x float> %nx)
+ %ny = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> %y)
+ %r = shufflevector <2 x float> %nx, <2 x float> %ny, <4 x i32> <i32 poison, i32 1, i32 2, i32 3>
+ ret <4 x float> %r
+}
+
+define <2 x float> @fabs_shuf_narrow_use2(<4 x float> %x, <4 x float> %y) {
+; CHECK-LABEL: @fabs_shuf_narrow_use2(
+; CHECK-NEXT: [[NX:%.*]] = call nnan nsz <4 x float> @llvm.fabs.v4f32(<4 x float> [[X:%.*]])
+; CHECK-NEXT: [[NY:%.*]] = call nnan nsz <4 x float> @llvm.fabs.v4f32(<4 x float> [[Y:%.*]])
+; CHECK-NEXT: call void @use4(<4 x float> [[NY]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[NX]], <4 x float> [[NY]], <2 x i32> <i32 3, i32 5>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %nx = call nsz nnan <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+ %ny = call nsz nnan <4 x float> @llvm.fabs.v4f32(<4 x float> %y)
+ call void @use4(<4 x float> %ny)
+ %r = shufflevector <4 x float> %nx, <4 x float> %ny, <2 x i32> <i32 3, i32 5>
+ ret <2 x float> %r
+}
+
+define <2 x float> @fabs_shuf_use3(<2 x float> %x, <2 x float> %y) {
+; CHECK-LABEL: @fabs_shuf_use3(
+; CHECK-NEXT: [[NX:%.*]] = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: call void @use(<2 x float> [[NX]])
+; CHECK-NEXT: [[NY:%.*]] = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> [[Y:%.*]])
+; CHECK-NEXT: call void @use(<2 x float> [[NY]])
+; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x float> [[NX]], <2 x float> [[NY]], <2 x i32> <i32 1, i32 2>
+; CHECK-NEXT: ret <2 x float> [[R]]
+;
+ %nx = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> %x)
+ call void @use(<2 x float> %nx)
+ %ny = call nnan <2 x float> @llvm.fabs.v2f32(<2 x float> %y)
+ call void @use(<2 x float> %ny)
+ %r = shufflevector <2 x float> %nx, <2 x float> %ny, <2 x i32> <i32 1, i32 2>
+ ret <2 x float> %r
+}
+
define <2 x float> @fneg_unary_shuf(<2 x float> %x) {
; CHECK-LABEL: @fneg_unary_shuf(
; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <2 x float> [[X:%.*]], <2 x float> poison, <2 x i32> <i32 1, i32 0>
ret <2 x float> %r
}
+define <4 x float> @fabs_fneg_shuf(<4 x float> %x, <4 x float> %y) {
+; CHECK-LABEL: @fabs_fneg_shuf(
+; CHECK-NEXT: [[NX:%.*]] = call <4 x float> @llvm.fabs.v4f32(<4 x float> [[X:%.*]])
+; CHECK-NEXT: [[NY:%.*]] = fneg nnan ninf <4 x float> [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = shufflevector <4 x float> [[NX]], <4 x float> [[NY]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+; CHECK-NEXT: ret <4 x float> [[R]]
+;
+ %nx = call <4 x float> @llvm.fabs.v4f32(<4 x float> %x)
+ %ny = fneg nnan ninf <4 x float> %y
+ %r = shufflevector <4 x float> %nx, <4 x float> %ny, <4 x i32> <i32 0, i32 1, i32 4, i32 5>
+ ret <4 x float> %r
+}
+
define <2 x i32> @fptosi_unary_shuf(<2 x float> %x) {
; CHECK-LABEL: @fptosi_unary_shuf(
; CHECK-NEXT: [[NX:%.*]] = fptosi <2 x float> [[X:%.*]] to <2 x i32>