[llvm] 0f4d592 - [InstCombine] add tests for shuffle-of-fabs; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 3 06:30:04 PST 2023


Author: Sanjay Patel
Date: 2023-02-03T09:26:58-05:00
New Revision: 0f4d5925b9315d41c14f43e44a36a9c15c3692a9

URL: https://github.com/llvm/llvm-project/commit/0f4d5925b9315d41c14f43e44a36a9c15c3692a9
DIFF: https://github.com/llvm/llvm-project/commit/0f4d5925b9315d41c14f43e44a36a9c15c3692a9.diff

LOG: [InstCombine] add tests for shuffle-of-fabs; NFC

Adapted from the existing shuffle-of-fneg tests.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstCombine/vec_shuffle.ll b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
index fdbd9c14f95be..f632f8b96810f 100644
--- a/llvm/test/Transforms/InstCombine/vec_shuffle.ll
+++ b/llvm/test/Transforms/InstCombine/vec_shuffle.ll
@@ -1,6 +1,12 @@
 ; 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:%.*]]
@@ -231,8 +237,8 @@ define <2 x i8> @test13a(i8 %x1, i8 %x2) {
 ; 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
@@ -280,8 +286,8 @@ define <3 x i32> @div_wider(i32 %y, i32 %z) {
 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
@@ -302,8 +308,8 @@ define <2 x i8> @test13b(i8 %x) {
 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
@@ -1789,6 +1795,112 @@ define <4 x i32> @PR46872(<4 x i32> %x) {
   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>
@@ -1904,6 +2016,19 @@ define <2 x float> @fneg_shuf_use3(<2 x float> %x, <2 x float> %y) {
   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>


        


More information about the llvm-commits mailing list