-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[VectorCombine] Scalarize binop-like intrinsics #138095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lukel97
merged 14 commits into
llvm:main
from
lukel97:vector-combine/scalarize-intrinsics
May 21, 2025
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1d031ea
Precommit tests
lukel97 ebfcbe4
[VectorCombine] Scalarize binop-like intrinsics
lukel97 4374304
clang-format
lukel97 968f061
Check isVectorIntrinsicWithScalarOpAtArg
lukel97 d559e15
Just check all arguments have same type as return
lukel97 3c3f7e3
Fix vector ICA type, add llvm_unreachable
lukel97 fea2417
Fix comment typo
lukel97 51dccf3
Merge branch 'main' of github.com:llvm/llvm-project into vector-combi…
lukel97 fbce2ad
Replace llvm_unreachable with cast
lukel97 c2f403d
Move tests out of RISC-V folder
lukel97 50789af
Merge branch 'main' into vector-combine/scalarize-intrinsics
lukel97 3f305fd
Add test case for x86 maxnum
lukel97 766f33d
Merge branch 'main' into vector-combine/scalarize-intrinsics
lukel97 befd9ba
Merge branch 'main' into vector-combine/scalarize-intrinsics
lukel97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
llvm/test/Transforms/VectorCombine/RISCV/intrinsic-scalarize.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -S -p vector-combine | FileCheck %s | ||
|
||
define <4 x i32> @umax_fixed(i32 %x, i32 %y) { | ||
; CHECK-LABEL: define <4 x i32> @umax_fixed( | ||
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]]) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.umax.v4i32(<4 x i32> poison, <4 x i32> poison) | ||
lukel97 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
; CHECK-NEXT: [[V:%.*]] = insertelement <4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <4 x i32> poison, i32 %x, i32 0 | ||
%y.insert = insertelement <4 x i32> poison, i32 %y, i32 0 | ||
%v = call <4 x i32> @llvm.umax(<4 x i32> %x.insert, <4 x i32> %y.insert) | ||
ret <4 x i32> %v | ||
} | ||
|
||
define <vscale x 4 x i32> @umax_scalable(i32 %x, i32 %y) { | ||
; CHECK-LABEL: define <vscale x 4 x i32> @umax_scalable( | ||
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 [[Y]]) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <vscale x 4 x i32> @llvm.umax.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> poison) | ||
; CHECK-NEXT: [[V:%.*]] = insertelement <vscale x 4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <vscale x 4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <vscale x 4 x i32> poison, i32 %x, i32 0 | ||
%y.insert = insertelement <vscale x 4 x i32> poison, i32 %y, i32 0 | ||
%v = call <vscale x 4 x i32> @llvm.umax(<vscale x 4 x i32> %x.insert, <vscale x 4 x i32> %y.insert) | ||
ret <vscale x 4 x i32> %v | ||
} | ||
|
||
define <4 x i32> @umax_fixed_lhs_const(i32 %x) { | ||
; CHECK-LABEL: define <4 x i32> @umax_fixed_lhs_const( | ||
; CHECK-SAME: i32 [[X:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 1, i32 [[X]]) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.umax.v4i32(<4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32> poison) | ||
; CHECK-NEXT: [[V:%.*]] = insertelement <4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <4 x i32> poison, i32 %x, i32 0 | ||
%v = call <4 x i32> @llvm.umax(<4 x i32> <i32 1, i32 2, i32 3, i32 4>, <4 x i32> %x.insert) | ||
ret <4 x i32> %v | ||
} | ||
|
||
define <4 x i32> @umax_fixed_rhs_const(i32 %x) { | ||
; CHECK-LABEL: define <4 x i32> @umax_fixed_rhs_const( | ||
; CHECK-SAME: i32 [[X:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 1) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <4 x i32> @llvm.umax.v4i32(<4 x i32> poison, <4 x i32> <i32 1, i32 2, i32 3, i32 4>) | ||
; CHECK-NEXT: [[V:%.*]] = insertelement <4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <4 x i32> poison, i32 %x, i32 0 | ||
%v = call <4 x i32> @llvm.umax(<4 x i32> %x.insert, <4 x i32> <i32 1, i32 2, i32 3, i32 4>) | ||
ret <4 x i32> %v | ||
} | ||
|
||
define <vscale x 4 x i32> @umax_scalable_lhs_const(i32 %x) { | ||
; CHECK-LABEL: define <vscale x 4 x i32> @umax_scalable_lhs_const( | ||
; CHECK-SAME: i32 [[X:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 42, i32 [[X]]) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <vscale x 4 x i32> @llvm.umax.nxv4i32(<vscale x 4 x i32> splat (i32 42), <vscale x 4 x i32> poison) | ||
; CHECK-NEXT: [[V:%.*]] = insertelement <vscale x 4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <vscale x 4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <vscale x 4 x i32> poison, i32 %x, i32 0 | ||
%v = call <vscale x 4 x i32> @llvm.umax(<vscale x 4 x i32> splat (i32 42), <vscale x 4 x i32> %x.insert) | ||
ret <vscale x 4 x i32> %v | ||
} | ||
|
||
define <vscale x 4 x i32> @umax_scalable_rhs_const(i32 %x) { | ||
; CHECK-LABEL: define <vscale x 4 x i32> @umax_scalable_rhs_const( | ||
; CHECK-SAME: i32 [[X:%.*]]) { | ||
; CHECK-NEXT: [[V_SCALAR:%.*]] = call i32 @llvm.umax.i32(i32 [[X]], i32 42) | ||
; CHECK-NEXT: [[TMP1:%.*]] = call <vscale x 4 x i32> @llvm.umax.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> splat (i32 42)) | ||
; CHECK-NEXT: [[V:%.*]] = insertelement <vscale x 4 x i32> [[TMP1]], i32 [[V_SCALAR]], i64 0 | ||
; CHECK-NEXT: ret <vscale x 4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <vscale x 4 x i32> poison, i32 %x, i32 0 | ||
%v = call <vscale x 4 x i32> @llvm.umax(<vscale x 4 x i32> %x.insert, <vscale x 4 x i32> splat (i32 42)) | ||
ret <vscale x 4 x i32> %v | ||
} | ||
|
||
; Shouldn't be scalarized, not a "trivially vectorizable" intrinsic. | ||
define <4 x i32> @non_trivially_vectorizable(i32 %x, i32 %y) { | ||
; CHECK-LABEL: define <4 x i32> @non_trivially_vectorizable( | ||
; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) { | ||
; CHECK-NEXT: [[X_INSERT:%.*]] = insertelement <4 x i32> poison, i32 [[X]], i32 0 | ||
; CHECK-NEXT: [[Y_INSERT:%.*]] = insertelement <8 x i32> poison, i32 [[Y]], i32 0 | ||
; CHECK-NEXT: [[V:%.*]] = call <4 x i32> @llvm.experimental.vector.partial.reduce.add.v4i32.v8i32(<4 x i32> [[X_INSERT]], <8 x i32> [[Y_INSERT]]) | ||
; CHECK-NEXT: ret <4 x i32> [[V]] | ||
; | ||
%x.insert = insertelement <4 x i32> poison, i32 %x, i32 0 | ||
%y.insert = insertelement <8 x i32> poison, i32 %y, i32 0 | ||
%v = call <4 x i32> @llvm.experimental.vector.partial.reduce.add(<4 x i32> %x.insert, <8 x i32> %y.insert) | ||
ret <4 x i32> %v | ||
} | ||
|
||
; TODO: We should be able to scalarize this if we preserve the scalar argument. | ||
define <4 x float> @scalar_argument(float %x) { | ||
; CHECK-LABEL: define <4 x float> @scalar_argument( | ||
; CHECK-SAME: float [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_INSERT:%.*]] = insertelement <4 x float> poison, float [[X]], i32 0 | ||
; CHECK-NEXT: [[V:%.*]] = call <4 x float> @llvm.powi.v4f32.i32(<4 x float> [[X_INSERT]], i32 42) | ||
; CHECK-NEXT: ret <4 x float> [[V]] | ||
; | ||
%x.insert = insertelement <4 x float> poison, float %x, i32 0 | ||
%v = call <4 x float> @llvm.powi(<4 x float> %x.insert, i32 42) | ||
ret <4 x float> %v | ||
} | ||
|
||
define <4 x i2> @scmp(i32 %x) { | ||
; CHECK-LABEL: define <4 x i2> @scmp( | ||
; CHECK-SAME: i32 [[X:%.*]]) { | ||
; CHECK-NEXT: [[X_INSERT:%.*]] = insertelement <4 x i32> poison, i32 [[X]], i32 0 | ||
; CHECK-NEXT: [[V:%.*]] = call <4 x i2> @llvm.scmp.v4i2.v4i32(<4 x i32> [[X_INSERT]], <4 x i32> zeroinitializer) | ||
; CHECK-NEXT: ret <4 x i2> [[V]] | ||
; | ||
%x.insert = insertelement <4 x i32> poison, i32 %x, i32 0 | ||
%v = call <4 x i2> @llvm.scmp(<4 x i32> %x.insert, <4 x i32> splat (i32 0)) | ||
ret <4 x i2> %v | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.