[llvm] 629e1e8 - [InstCombine] add tests for funnel-shift with shuffled operands; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 10:07:40 PDT 2022


Author: Sanjay Patel
Date: 2022-05-04T13:07:26-04:00
New Revision: 629e1e82e45864fd959d3abfa2ac77eb7b9e180f

URL: https://github.com/llvm/llvm-project/commit/629e1e82e45864fd959d3abfa2ac77eb7b9e180f
DIFF: https://github.com/llvm/llvm-project/commit/629e1e82e45864fd959d3abfa2ac77eb7b9e180f.diff

LOG: [InstCombine] add tests for funnel-shift with shuffled operands; NFC

Added: 
    

Modified: 
    llvm/test/Transforms/InstCombine/fsh.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/fsh.ll b/llvm/test/Transforms/InstCombine/fsh.ll
index b1e8499d58f67..8d5d5e004d970 100644
--- a/llvm/test/Transforms/InstCombine/fsh.ll
+++ b/llvm/test/Transforms/InstCombine/fsh.ll
@@ -1,10 +1,16 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 
+declare i16 @llvm.fshl.i16(i16, i16, i16)
+declare i16 @llvm.fshr.i16(i16, i16, i16)
 declare i32 @llvm.fshl.i32(i32, i32, i32)
 declare i33 @llvm.fshr.i33(i33, i33, i33)
 declare <2 x i32> @llvm.fshr.v2i32(<2 x i32>, <2 x i32>, <2 x i32>)
 declare <2 x i31> @llvm.fshl.v2i31(<2 x i31>, <2 x i31>, <2 x i31>)
+declare <3 x i16> @llvm.fshl.v3i16(<3 x i16>, <3 x i16>, <3 x i16>)
+
+declare void @use_v2(<2 x i31>)
+declare void @use_v3(<3 x i16>)
 
 ; If the shift mask doesn't include any demanded bits, the funnel shift can be eliminated.
 
@@ -592,10 +598,6 @@ define i33 @expanded_fshr_multi_use(i33 %a) {
   ret i33 %e
 }
 
-declare i16 @llvm.fshl.i16(i16, i16, i16)
-declare i16 @llvm.fshr.i16(i16, i16, i16)
-declare <3 x i16> @llvm.fshl.v3i16(<3 x i16>, <3 x i16>, <3 x i16>)
-
 ; Special-case: rotate a 16-bit value left/right by 8-bits is bswap.
 
 define i16 @fshl_bswap(i16 %x) {
@@ -735,3 +737,107 @@ define <2 x i31> @fshr_mask_args_same_vector3_
diff erent_but_still_prunable(<2 x
   %t3 = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %t2, <2 x i31> %t1, <2 x i31> <i31 10, i31 3>)
   ret <2 x i31> %t3
 }
+
+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> <i32 1, i32 0>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <2 x i32> [[Y:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[C:%.*]] = shufflevector <2 x i32> [[Z:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[A]], <2 x i32> [[B]], <2 x i32> [[C]])
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %a = shufflevector <2 x i32> %x, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %b = shufflevector <2 x i32> %y, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %c = shufflevector <2 x i32> %z, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
+  ret <2 x i32> %r
+}
+
+define <3 x i16> @fsh_unary_shuffle_ops_widening(<2 x i16> %x, <2 x i16> %y, <2 x i16> %z) {
+; CHECK-LABEL: @fsh_unary_shuffle_ops_widening(
+; CHECK-NEXT:    [[A:%.*]] = shufflevector <2 x i16> [[X:%.*]], <2 x i16> poison, <3 x i32> <i32 1, i32 0, i32 1>
+; 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> <i32 1, i32 0, i32 1>
+; CHECK-NEXT:    [[C:%.*]] = shufflevector <2 x i16> [[Z:%.*]], <2 x i16> poison, <3 x i32> <i32 1, i32 0, i32 1>
+; CHECK-NEXT:    [[R:%.*]] = call <3 x i16> @llvm.fshl.v3i16(<3 x i16> [[A]], <3 x i16> [[B]], <3 x i16> [[C]])
+; CHECK-NEXT:    ret <3 x i16> [[R]]
+;
+  %a = shufflevector <2 x i16> %x, <2 x i16> poison, <3 x i32> <i32 1, i32 0, i32 1>
+  call void @use_v3(<3 x i16> %a)
+  %b = shufflevector <2 x i16> %y, <2 x i16> poison, <3 x i32> <i32 1, i32 0, i32 1>
+  %c = shufflevector <2 x i16> %z, <2 x i16> poison, <3 x i32> <i32 1, i32 0, i32 1>
+  %r = call <3 x i16> @llvm.fshl.v3i16(<3 x i16> %a, <3 x i16> %b, <3 x i16> %c)
+  ret <3 x i16> %r
+}
+
+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> <i32 1, i32 0>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <3 x i31> [[Y:%.*]], <3 x i31> poison, <2 x i32> <i32 1, i32 0>
+; 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> <i32 1, i32 0>
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[A]], <2 x i31> [[B]], <2 x i31> [[C]])
+; CHECK-NEXT:    ret <2 x i31> [[R]]
+;
+  %a = shufflevector <3 x i31> %x, <3 x i31> poison, <2 x i32> <i32 1, i32 0>
+  %b = shufflevector <3 x i31> %y, <3 x i31> poison, <2 x i32> <i32 1, i32 0>
+  call void @use_v2(<2 x i31> %b)
+  %c = shufflevector <3 x i31> %z, <3 x i31> poison, <2 x i32> <i32 1, i32 0>
+  %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %a, <2 x i31> %b, <2 x i31> %c)
+  ret <2 x i31> %r
+}
+
+; negative test - must have 3 shuffles
+
+define <2 x i32> @fsh_unary_shuffle_ops_unshuffled(<2 x i32> %x, <2 x i32> %y, <2 x i32> %z) {
+; CHECK-LABEL: @fsh_unary_shuffle_ops_unshuffled(
+; CHECK-NEXT:    [[A:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <2 x i32> [[Y:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[A]], <2 x i32> [[B]], <2 x i32> [[Z:%.*]])
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %a = shufflevector <2 x i32> %x, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %b = shufflevector <2 x i32> %y, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %z)
+  ret <2 x i32> %r
+}
+
+; negative test - must have identical masks
+
+define <2 x i32> @fsh_unary_shuffle_ops_wrong_mask(<2 x i32> %x, <2 x i32> %y, <2 x i32> %z) {
+; CHECK-LABEL: @fsh_unary_shuffle_ops_wrong_mask(
+; CHECK-NEXT:    [[A:%.*]] = shufflevector <2 x i32> [[X:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <2 x i32> [[Y:%.*]], <2 x i32> poison, <2 x i32> zeroinitializer
+; CHECK-NEXT:    [[C:%.*]] = shufflevector <2 x i32> [[Z:%.*]], <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> [[A]], <2 x i32> [[B]], <2 x i32> [[C]])
+; CHECK-NEXT:    ret <2 x i32> [[R]]
+;
+  %a = shufflevector <2 x i32> %x, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %b = shufflevector <2 x i32> %y, <2 x i32> poison, <2 x i32> <i32 0, i32 0>
+  %c = shufflevector <2 x i32> %z, <2 x i32> poison, <2 x i32> <i32 1, i32 0>
+  %r = call <2 x i32> @llvm.fshr.v2i32(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c)
+  ret <2 x i32> %r
+}
+
+; negative test - too many uses
+
+define <2 x i31> @fsh_unary_shuffle_ops_uses(<2 x i31> %x, <2 x i31> %y, <2 x i31> %z) {
+; CHECK-LABEL: @fsh_unary_shuffle_ops_uses(
+; CHECK-NEXT:    [[A:%.*]] = shufflevector <2 x i31> [[X:%.*]], <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    call void @use_v2(<2 x i31> [[A]])
+; CHECK-NEXT:    [[B:%.*]] = shufflevector <2 x i31> [[Y:%.*]], <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    call void @use_v2(<2 x i31> [[B]])
+; CHECK-NEXT:    [[C:%.*]] = shufflevector <2 x i31> [[Z:%.*]], <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+; CHECK-NEXT:    call void @use_v2(<2 x i31> [[C]])
+; CHECK-NEXT:    [[R:%.*]] = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> [[A]], <2 x i31> [[B]], <2 x i31> [[C]])
+; CHECK-NEXT:    ret <2 x i31> [[R]]
+;
+  %a = shufflevector <2 x i31> %x, <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+  call void @use_v2(<2 x i31> %a)
+  %b = shufflevector <2 x i31> %y, <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+  call void @use_v2(<2 x i31> %b)
+  %c = shufflevector <2 x i31> %z, <2 x i31> poison, <2 x i32> <i32 1, i32 0>
+  call void @use_v2(<2 x i31> %c)
+  %r = call <2 x i31> @llvm.fshl.v2i31(<2 x i31> %a, <2 x i31> %b, <2 x i31> %c)
+  ret <2 x i31> %r
+}


        


More information about the llvm-commits mailing list