From: Bjorn Pettersson Date: Mon, 24 Jun 2019 12:07:11 +0000 (+0000) Subject: [Scalarizer] Add scalarizer support for smul.fix.sat X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dfff6fc1d873d016e22edc84cb2829f906ea9abf;p=llvm [Scalarizer] Add scalarizer support for smul.fix.sat Summary: Handle smul.fix.sat in the scalarizer. This is done by adding smul.fix.sat to the set of "isTriviallyVectorizable" intrinsics. The addition of smul.fix.sat in isTriviallyVectorizable and hasVectorInstrinsicScalarOpd can also be seen as a preparation to be able to use hasVectorInstrinsicScalarOpd in ConstantFolding. Reviewers: rengolin, RKSimon, dblaikie Reviewed By: rengolin Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63704 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364177 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/VectorUtils.h b/include/llvm/Analysis/VectorUtils.h index ac358859437..d93d2bc4570 100644 --- a/include/llvm/Analysis/VectorUtils.h +++ b/include/llvm/Analysis/VectorUtils.h @@ -36,13 +36,12 @@ enum ID : unsigned; } /// Identify if the intrinsic is trivially vectorizable. -/// This method returns true if the intrinsic's argument types are all -/// scalars for the scalar form of the intrinsic and all vectors for -/// the vector form of the intrinsic. +/// This method returns true if the intrinsic's argument types are all scalars +/// for the scalar form of the intrinsic and all vectors (or scalars handled by +/// hasVectorInstrinsicScalarOpd) for the vector form of the intrinsic. bool isTriviallyVectorizable(Intrinsic::ID ID); -/// Identifies if the intrinsic has a scalar operand. It checks for -/// ctlz,cttz and powi special intrinsics whose argument is scalar. +/// Identifies if the vector form of the intrinsic has a scalar operand. bool hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx); /// Returns intrinsic ID for call. diff --git a/lib/Analysis/VectorUtils.cpp b/lib/Analysis/VectorUtils.cpp index 8040af12d7c..986756eb262 100644 --- a/lib/Analysis/VectorUtils.cpp +++ b/lib/Analysis/VectorUtils.cpp @@ -37,8 +37,9 @@ static cl::opt MaxInterleaveGroupFactor( cl::init(8)); /// Return true if all of the intrinsic's arguments and return type are scalars -/// for the scalar form of the intrinsic and vectors for the vector form of the -/// intrinsic. +/// for the scalar form of the intrinsic, and vectors for the vector form of the +/// intrinsic (except operands that are marked as always being scalar by +/// hasVectorInstrinsicScalarOpd). bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) { switch (ID) { case Intrinsic::bswap: // Begin integer bit-manipulation. @@ -53,6 +54,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) { case Intrinsic::uadd_sat: case Intrinsic::usub_sat: case Intrinsic::smul_fix: + case Intrinsic::smul_fix_sat: case Intrinsic::umul_fix: case Intrinsic::sqrt: // Begin floating-point. case Intrinsic::sin: @@ -85,8 +87,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) { } } -/// Identifies if the intrinsic has a scalar operand. It check for -/// ctlz,cttz and powi special intrinsics whose argument is scalar. +/// Identifies if the vector form of the intrinsic has a scalar operand. bool llvm::hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, unsigned ScalarOpdIdx) { switch (ID) { @@ -95,6 +96,7 @@ bool llvm::hasVectorInstrinsicScalarOpd(Intrinsic::ID ID, case Intrinsic::powi: return (ScalarOpdIdx == 1); case Intrinsic::smul_fix: + case Intrinsic::smul_fix_sat: case Intrinsic::umul_fix: return (ScalarOpdIdx == 2); default: diff --git a/test/Transforms/Scalarizer/intrinsics.ll b/test/Transforms/Scalarizer/intrinsics.ll index 7cd324122d9..dcd44fa373a 100644 --- a/test/Transforms/Scalarizer/intrinsics.ll +++ b/test/Transforms/Scalarizer/intrinsics.ll @@ -12,7 +12,7 @@ declare <2 x float> @llvm.maximum.v2f32(<2 x float>, <2 x float>) ; Ternary fp declare <2 x float> @llvm.fma.v2f32(<2 x float>, <2 x float>, <2 x float>) -; Binary int +; Unary int declare <2 x i32> @llvm.bswap.v2i32(<2 x i32>) ; Unary int plus constant scalar operand @@ -21,6 +21,10 @@ declare <2 x i32> @llvm.ctlz.v2i32(<2 x i32>, i1) ; Unary fp plus any scalar operand declare <2 x float> @llvm.powi.v2f32(<2 x float>, i32) +; Binary int plus constant scalar operand +declare <2 x i32> @llvm.smul.fix.sat.v2i32(<2 x i32>, <2 x i32>, i32) + + ; CHECK-LABEL: @scalarize_sqrt_v2f32( ; CHECK: %sqrt.i0 = call float @llvm.sqrt.f32(float %x.i0) ; CHECK: %sqrt.i1 = call float @llvm.sqrt.f32(float %x.i1) @@ -108,3 +112,14 @@ define <2 x float> @scalarize_powi_v2f32(<2 x float> %x, i32 %y) #0 { %powi = call <2 x float> @llvm.powi.v2f32(<2 x float> %x, i32 %y) ret <2 x float> %powi } + +; CHECK-LABEL: @scalarize_smul_fix_sat_v2i32( +; CHECK: %smulfixsat.i0 = call i32 @llvm.smul.fix.sat.i32(i32 %x.i0, i32 5, i32 31) +; CHECK: %smulfixsat.i1 = call i32 @llvm.smul.fix.sat.i32(i32 %x.i1, i32 19, i32 31) +; CHECK: %smulfixsat.upto0 = insertelement <2 x i32> undef, i32 %smulfixsat.i0, i32 0 +; CHECK: %smulfixsat = insertelement <2 x i32> %smulfixsat.upto0, i32 %smulfixsat.i1, i32 1 +; CHECK: ret <2 x i32> %smulfixsat +define <2 x i32> @scalarize_smul_fix_sat_v2i32(<2 x i32> %x) #0 { + %smulfixsat = call <2 x i32> @llvm.smul.fix.sat.v2i32(<2 x i32> %x, <2 x i32> , i32 31) + ret <2 x i32> %smulfixsat +}