; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -passes=vector-combine -S -mtriple=aarch64 %s | FileCheck %s ; This file tests the foldPermuteOfIntrinsic optimization which transforms: ; shuffle(intrinsic(args), poison) -> intrinsic(shuffle(args)) ; when the shuffle is a permute (operates on single vector) and cost model ; determines the transformation is beneficial. ;; ============================================================================ ;; Positive Tests - Should Optimize ;; ============================================================================ define <4 x i32> @extract_lower_sadd_sat(<8 x i32> %v1, <8 x i32> %v2) { ; CHECK-LABEL: @extract_lower_sadd_sat( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[V1:%.*]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i32> [[V2:%.*]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> [[TMP1]], <4 x i32> [[TMP2]]) ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %sat = call <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32> %v1, <8 x i32> %v2) %result = shufflevector <8 x i32> %sat, <8 x i32> poison, <4 x i32> ret <4 x i32> %result } define <4 x i32> @extract_lower_uadd_sat(<8 x i32> %v1, <8 x i32> %v2) { ; CHECK-LABEL: @extract_lower_uadd_sat( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[V1:%.*]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x i32> [[V2:%.*]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32> [[TMP1]], <4 x i32> [[TMP2]]) ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %sat = call <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32> %v1, <8 x i32> %v2) %result = shufflevector <8 x i32> %sat, <8 x i32> poison, <4 x i32> ret <4 x i32> %result } define <4 x float> @extract_lower_fma(<8 x float> %a, <8 x float> %b, <8 x float> %c) { ; CHECK-LABEL: @extract_lower_fma( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x float> [[A:%.*]], <8 x float> poison, <4 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <8 x float> [[B:%.*]], <8 x float> poison, <4 x i32> ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <8 x float> [[C:%.*]], <8 x float> poison, <4 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <4 x float> @llvm.fma.v4f32(<4 x float> [[TMP1]], <4 x float> [[TMP2]], <4 x float> [[TMP3]]) ; CHECK-NEXT: ret <4 x float> [[RESULT]] ; %fma = call <8 x float> @llvm.fma.v8f32(<8 x float> %a, <8 x float> %b, <8 x float> %c) %result = shufflevector <8 x float> %fma, <8 x float> poison, <4 x i32> ret <4 x float> %result } define <4 x i32> @extract_lower_abs_should_not_shuffle_scalar(<8 x i32> %v) { ; CHECK-LABEL: @extract_lower_abs_should_not_shuffle_scalar( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <8 x i32> [[V:%.*]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <4 x i32> @llvm.abs.v4i32(<4 x i32> [[TMP1]], i1 false) ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %abs = call <8 x i32> @llvm.abs.v8i32(<8 x i32> %v, i1 false) %result = shufflevector <8 x i32> %abs, <8 x i32> poison, <4 x i32> ret <4 x i32> %result } define <2 x i64> @extract_lower_i64(<4 x i64> %v1, <4 x i64> %v2) { ; CHECK-LABEL: @extract_lower_i64( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i64> [[V1:%.*]], <4 x i64> poison, <2 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <4 x i64> [[V2:%.*]], <4 x i64> poison, <2 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <2 x i64> @llvm.sadd.sat.v2i64(<2 x i64> [[TMP1]], <2 x i64> [[TMP2]]) ; CHECK-NEXT: ret <2 x i64> [[RESULT]] ; %sat = call <4 x i64> @llvm.sadd.sat.v4i64(<4 x i64> %v1, <4 x i64> %v2) %result = shufflevector <4 x i64> %sat, <4 x i64> poison, <2 x i32> ret <2 x i64> %result } define <8 x i16> @extract_lower_i16(<16 x i16> %v1, <16 x i16> %v2) { ; CHECK-LABEL: @extract_lower_i16( ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <16 x i16> [[V1:%.*]], <16 x i16> poison, <8 x i32> ; CHECK-NEXT: [[TMP2:%.*]] = shufflevector <16 x i16> [[V2:%.*]], <16 x i16> poison, <8 x i32> ; CHECK-NEXT: [[RESULT:%.*]] = call <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16> [[TMP1]], <8 x i16> [[TMP2]]) ; CHECK-NEXT: ret <8 x i16> [[RESULT]] ; %sat = call <16 x i16> @llvm.sadd.sat.v16i16(<16 x i16> %v1, <16 x i16> %v2) %result = shufflevector <16 x i16> %sat, <16 x i16> poison, <8 x i32> ret <8 x i16> %result } ;; ============================================================================ ;; Negative Tests - Should NOT Optimize ;; ============================================================================ define <4 x i32> @same_size_permute(<4 x i32> %v1, <4 x i32> %v2) { ; CHECK-LABEL: @same_size_permute( ; CHECK-NEXT: [[SAT:%.*]] = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> [[V1:%.*]], <4 x i32> [[V2:%.*]]) ; CHECK-NEXT: [[RESULT:%.*]] = shufflevector <4 x i32> [[SAT]], <4 x i32> poison, <4 x i32> ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %sat = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %v1, <4 x i32> %v2) %result = shufflevector <4 x i32> %sat, <4 x i32> poison, <4 x i32> ret <4 x i32> %result } define <4 x i32> @not_a_permute_uses_second_operand(<4 x i32> %v1, <4 x i32> %v2, <4 x i32> %other) { ; CHECK-LABEL: @not_a_permute_uses_second_operand( ; CHECK-NEXT: [[SAT:%.*]] = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> [[V1:%.*]], <4 x i32> [[V2:%.*]]) ; CHECK-NEXT: [[RESULT:%.*]] = shufflevector <4 x i32> [[SAT]], <4 x i32> [[OTHER:%.*]], <4 x i32> ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %sat = call <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32> %v1, <4 x i32> %v2) %result = shufflevector <4 x i32> %sat, <4 x i32> %other, <4 x i32> ret <4 x i32> %result } define <4 x i32> @not_an_intrinsic(<8 x i32> %v1, <8 x i32> %v2) { ; CHECK-LABEL: @not_an_intrinsic( ; CHECK-NEXT: [[ADD:%.*]] = add <8 x i32> [[V1:%.*]], [[V2:%.*]] ; CHECK-NEXT: [[RESULT:%.*]] = shufflevector <8 x i32> [[ADD]], <8 x i32> poison, <4 x i32> ; CHECK-NEXT: ret <4 x i32> [[RESULT]] ; %add = add <8 x i32> %v1, %v2 %result = shufflevector <8 x i32> %add, <8 x i32> poison, <4 x i32> ret <4 x i32> %result } declare <8 x i32> @llvm.sadd.sat.v8i32(<8 x i32>, <8 x i32>) declare <4 x i32> @llvm.sadd.sat.v4i32(<4 x i32>, <4 x i32>) declare <4 x i64> @llvm.sadd.sat.v4i64(<4 x i64>, <4 x i64>) declare <2 x i64> @llvm.sadd.sat.v2i64(<2 x i64>, <2 x i64>) declare <16 x i16> @llvm.sadd.sat.v16i16(<16 x i16>, <16 x i16>) declare <8 x i16> @llvm.sadd.sat.v8i16(<8 x i16>, <8 x i16>) declare <8 x i32> @llvm.uadd.sat.v8i32(<8 x i32>, <8 x i32>) declare <4 x i32> @llvm.uadd.sat.v4i32(<4 x i32>, <4 x i32>) declare <8 x i32> @llvm.abs.v8i32(<8 x i32>, i1 immarg) declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1 immarg) declare <8 x float> @llvm.fma.v8f32(<8 x float>, <8 x float>, <8 x float>) declare <4 x float> @llvm.fma.v4f32(<4 x float>, <4 x float>, <4 x float>)