From 7e6d318c506bbbffb4f92cd8b70773beedc78c3e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 4 May 2022 12:44:47 -0400 Subject: [PATCH] [InstCombine] move shuffle after funnel shift with same-shuffled operands This extends 432c199e8473 and 9c4770eaab9d9 with an intrinsic cited directly in issue #46238 Eventually, we will want to use llvm::isTriviallyVectorizable() or create some new API for this list, but for now, I am intentionally making a minimum change to reduce risk and only affect an intrinsic with regression tests in place. --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 2 ++ llvm/test/Transforms/InstCombine/fsh.ll | 16 ++++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 485372c..f466f54 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1094,6 +1094,8 @@ foldShuffledIntrinsicOperands(IntrinsicInst *II, case Intrinsic::umax: case Intrinsic::umin: case Intrinsic::fma: + case Intrinsic::fshl: + case Intrinsic::fshr: break; default: return nullptr; diff --git a/llvm/test/Transforms/InstCombine/fsh.ll b/llvm/test/Transforms/InstCombine/fsh.ll index 8d5d5e0..8460fc8 100644 --- a/llvm/test/Transforms/InstCombine/fsh.ll +++ b/llvm/test/Transforms/InstCombine/fsh.ll @@ -740,10 +740,8 @@ define <2 x i31> @fshr_mask_args_same_vector3_different_but_still_prunable(<2 x define <2 x i32> @fsh_unary_shuffle_ops(<2 x i32> %x, <2 x i32> %y, <2 x i32> %z) { ; CHECK-LABEL: @fsh_unary_shuffle_ops( -; CHECK-NEXT: [[A:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> poison, <2 x i32> -; CHECK-NEXT: [[B:%.*]] = shufflevector <2 x i32> [[Y:%.*]], <2 x i32> poison, <2 x i32> -; CHECK-NEXT: [[C:%.*]] = shufflevector <2 x i32> [[Z:%.*]], <2 x i32> poison, <2 x i32> -; CHECK-NEXT: [[R:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[A]], <2 x i32> [[B]], <2 x i32> [[C]]) +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[X:%.*]], <2 x i32> [[Y:%.*]], <2 x i32> [[Z:%.*]]) +; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i32> [[TMP1]], <2 x i32> poison, <2 x i32> ; CHECK-NEXT: ret <2 x i32> [[R]] ; %a = shufflevector <2 x i32> %x, <2 x i32> poison, <2 x i32> @@ -757,9 +755,8 @@ define <3 x i16> @fsh_unary_shuffle_ops_widening(<2 x i16> %x, <2 x i16> %y, <2 ; CHECK-LABEL: @fsh_unary_shuffle_ops_widening( ; CHECK-NEXT: [[A:%.*]] = shufflevector <2 x i16> [[X:%.*]], <2 x i16> poison, <3 x i32> ; CHECK-NEXT: call void @use_v3(<3 x i16> [[A]]) -; CHECK-NEXT: [[B:%.*]] = shufflevector <2 x i16> [[Y:%.*]], <2 x i16> poison, <3 x i32> -; CHECK-NEXT: [[C:%.*]] = shufflevector <2 x i16> [[Z:%.*]], <2 x i16> poison, <3 x i32> -; CHECK-NEXT: [[R:%.*]] = call <3 x i16> @llvm.fshl.v3i16(<3 x i16> [[A]], <3 x i16> [[B]], <3 x i16> [[C]]) +; CHECK-NEXT: [[TMP1:%.*]] = call <2 x i16> @llvm.fshl.v2i16(<2 x i16> [[X]], <2 x i16> [[Y:%.*]], <2 x i16> [[Z:%.*]]) +; CHECK-NEXT: [[R:%.*]] = shufflevector <2 x i16> [[TMP1]], <2 x i16> poison, <3 x i32> ; CHECK-NEXT: ret <3 x i16> [[R]] ; %a = shufflevector <2 x i16> %x, <2 x i16> poison, <3 x i32> @@ -772,11 +769,10 @@ define <3 x i16> @fsh_unary_shuffle_ops_widening(<2 x i16> %x, <2 x i16> %y, <2 define <2 x i31> @fsh_unary_shuffle_ops_narrowing(<3 x i31> %x, <3 x i31> %y, <3 x i31> %z) { ; CHECK-LABEL: @fsh_unary_shuffle_ops_narrowing( -; CHECK-NEXT: [[A:%.*]] = shufflevector <3 x i31> [[X:%.*]], <3 x i31> poison, <2 x i32> ; CHECK-NEXT: [[B:%.*]] = shufflevector <3 x i31> [[Y:%.*]], <3 x i31> poison, <2 x i32> ; CHECK-NEXT: call void @use_v2(<2 x i31> [[B]]) -; CHECK-NEXT: [[C:%.*]] = shufflevector <3 x i31> [[Z:%.*]], <3 x i31> poison, <2 x i32> -; CHECK-NEXT: [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[A]], <2 x i31> [[B]], <2 x i31> [[C]]) +; CHECK-NEXT: [[TMP1:%.*]] = call <3 x i31> @llvm.fshl.v3i31(<3 x i31> [[X:%.*]], <3 x i31> [[Y]], <3 x i31> [[Z:%.*]]) +; CHECK-NEXT: [[R:%.*]] = shufflevector <3 x i31> [[TMP1]], <3 x i31> poison, <2 x i32> ; CHECK-NEXT: ret <2 x i31> [[R]] ; %a = shufflevector <3 x i31> %x, <3 x i31> poison, <2 x i32> -- 2.7.4